I'm coding my first python game using OOP and I have some problems with the access to class variables. Specifically, I want to have access to a class variable from a method. For some variables it works, but for a specific boolean variable it does not work:
class Player(object):
eaten = False
def __init__(self):
.....
def eat(Player):
Player.eaten = True
The problem is that, when the function is called, eaten does not override the variable in the class. For other variables it does correctly what I want though.
EDIT:
If, inside a method in the Class player, I add print(self.eaten)
after eat()
is called, it still prints always False
class Player(object):
eaten = False
def move():
print(self.eaten)
def eat(Player):
Player.eaten = True
Thank you!