At the moment, I am having an issue with keeping a players health from going above the max set health. This issue occurred to me after I had gotten combat working and came to the conclusion of making equipment and items that a character could equip and use. And that is when I realized that there was nothing keeping the health from going over the max health.
#This is the character template that PC's and NPC's have. #NPC's and the PC will have their own variables and attributes #to further differentiate them. class Character(object): def __init__(self, name, max_health, health, strength, stamina, toHit): self.name = name self.max_health = max_health self.health = health self.strength = strength self.stamina = stamina self.toHit = toHit def max_health(): if self.health => self.max_health: self.health = self.max_health #Health can never go above max health
My thought on a solution was to do an if statement that would check if the characters current health is above the max health that the health would then be set to the max health so it basically acted as a limit.
In my tests I would then set a variable to something like 'test = Character('John', 10, 10, 10, 10, 10)' and then increase the health by some number by doing 'test.health += 1' and then entering 'test.health' to see if my code worked.
That didn't work either. I will say that I originally had the if statement under the __init__ as well but then put it into it's own method to see if that worked. Neither have been working at all it seems.
I have also tried not setting any variable to self and have gotten no result either.
I am at my wits end as to how to get this working and would very much enjoy some assistance as I make my steps in learning how to program.