Aug-05-2019, 09:23 PM
Hello, again...
You guys recently replied to my post: https://python-forum.io/Thread-Modifying-Classes, and it was of great help to me I was able to implement it and expand it for what I needed, So thank you, that was awesome.
But, recently, I have come across a similar problem and I've spent a lot of time researching and trying to fix it, I was hoping you guys might be able to explain to me what I'm doing wrong.
My goal is to use a function to increase the level of 'dagger' by 1, but the function seems to have no effect at all on the result.
My other goal is to multiply the attribute value by the level value but it doesn't seem to be updated with the class I created.
Any advice would be greatly appreciated!
You guys recently replied to my post: https://python-forum.io/Thread-Modifying-Classes, and it was of great help to me I was able to implement it and expand it for what I needed, So thank you, that was awesome.
But, recently, I have come across a similar problem and I've spent a lot of time researching and trying to fix it, I was hoping you guys might be able to explain to me what I'm doing wrong.
My goal is to use a function to increase the level of 'dagger' by 1, but the function seems to have no effect at all on the result.
My other goal is to multiply the attribute value by the level value but it doesn't seem to be updated with the class I created.
Any advice would be greatly appreciated!
class weapon(): def __init__(self, Name = '', level = 0, xp = 0, xpnextlvl = 25): self.Name = Name self.level = level self.xp = xp self.xpnextlvl = xpnextlvl def __repr__(self): return str(vars(self)) class attributes(): def __init__(self, Strength = 0, Constitution = 0, Endurance = 0, Dexterity = 0, Intelligence = 0, Wisdom = 0, Charisma = 0, Perception = 0, Luck = 0): self.Strength = Strength * weapon().level # Not updating 'Strength' Value by what I inputted as 'Dagger' self.Constitution = Constitution self.Endurance = Endurance self.Dexterity = Dexterity self.Intelligence = Intelligence self.Wisdom = Wisdom self.Charisma = Charisma self.Perception = Perception self.Luck = Luck def __repr__(self): return str(vars(self)) def weapon_level(self): #This function seem to have no effect on the values for 'Dagger' print('Welcome to the blacksmith') print('1: Level up') print('2: Quit') choice = input('choose: ') level = self.level if choice == '1': level += 1 dagger = weapon('Dagger', 1, 0 , 25), weapon.attributes(1, 1, 1, 1, 1, 1, 1, 1, 1) weapon.weapon_level(weapon(dagger)) print(dagger)
Output:Welcome to the blacksmith
1: Level up
2: Quit
choose: 1
({'Name': 'Dagger', 'level': 1, 'xp': 0, 'xpnextlvl': 25}, {'Strength': 0, 'Constitution': 1, 'Endurance': 1, 'Dexterity': 1, 'Intelligence': 1, 'Wisdom': 1, 'Charisma': 1, 'Perception': 1, 'Luck': 1})
The output should have level: 2 and strength: 2