In my program I have setup two classes called game.py and player.py. Both files call upon functions within the Player class (everything is imported properly), and in the game.py file all the information about the variables is printed. However, when a variable is updated from the Game class the new variable is printed fine, but when it is updated from the Player class it does not change. Instead, the variables printed are the ones from the init in the Player class.
For example
(in the Game class)
print player.health
player.health += 1
print player.health
will print
100
101
whereas if i were to do
self.health += 100 #(from within the Player class)
and then
print player.health #(from the Game class)
the output would be
100
note: the variables are being updated within the Player class but aren't being printed properly from the Game class. but I know they're being update in Player because the user still dies when health reaches 0 even though it's constantly displayed as 100
I believe the cause is the variables are all being reset to the init variables in the Player class, but that wouldn't fully explain why the Game class can manipulate the variables permanently. Does it have something to do with self.?
Any help is greatly appreciate. Thanks!
edit: Adding the code where Game gets the player variable
purple("\n\nHealth: %d" % player.health)
purple is a function that turns the text purple, player is defined at the start of the class as
player = Player()
it is no longer defined in any other file
Game
code getting itsplayer
instance? Could it be modifying a different instance than your other code?Game
by passing it aPlayer
instance, perhaps).