Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Modifying Class values
#1
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!

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
Reply


Messages In This Thread
Modifying Class values - by Tridium - Aug-05-2019, 09:23 PM
RE: Modifying Class values - by ichabod801 - Aug-05-2019, 09:52 PM
RE: Modifying Class values - by Tridium - Aug-05-2019, 10:29 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Modifying Classes Tridium 4 6,796 Aug-03-2019, 05:41 PM
Last Post: Tridium

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020