Question

So i have a problem, that i don't quite understand why it's happening. I get a (Name Error global variable "value" is not defined) when it should be on my weapons class.

from items import *

class weapons(Item):
    def __init__(self, name, attack_damage, lifesteal = 0):
        super(weapons,self).__init__(name, value, quantity=1)
        self.attack_damage = attack_damage
        self.lifesteal = lifesteal

Here is the class that weapons is getting it from that already has value defined.

class Item(object):
    def __init__(self, name, value, quantity=1):
        self.name = name
        self.raw = name.replace(" ","").lower()
        self.quantity = quantity
        self.value = value
        self.netValue = quantity * value
    def recalc(self):
        self.netValue = self.quantity * self.value

I already have a piece of code similar to this that is working, but for some reason this value error is happening. I'm just going to include it.

from character import*
class player(character):
    def __init__(self,name,hp,maxhp,attack_damage,ability_power):
        super(player,self).__init__(name, hp, maxhp)
        self.attack_damage = attack_damage
        self.ability_power = ability_power

and the class that player is getting its stuff from

class character(object):
    def __init__(self,name,hp,maxhp):
        self.name = name
        self.hp = hp
        self.maxhp = maxhp
    def attack(self,other):
        pass

as you can see i did it here and this piece of code works when i call a player.

Was it helpful?

Solution

You need to add the value argument to the __init__ constructor of the weapons class.

OTHER TIPS

super needs a parameter value but you did not pass it into the init

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top