Jotin2
Jotin2

Reputation: 39

Name Error python, a text adventure game

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.

Upvotes: 1

Views: 98

Answers (2)

Ramchandra Apte
Ramchandra Apte

Reputation: 4079

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

Upvotes: 2

Floris
Floris

Reputation: 46365

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

Upvotes: 0

Related Questions