1

So I'm trying to make an endless text adventure game (using help from this site), but I'm having some problems with my classes:

class Item:
def __init__(self, name, desc, usable, value):
 self.name = name
 self.desc = desc
 self.usable = usable
 self.value = value
def __str__(self):
 return "{}\n=====\n{}\nValue: {}\n".format(self.name, self.desc, self.usable, self.value)
class Weapon(Item):
 def __init__(self, damage):
 self.damage = damage
 super().__init__(desc, name, usable, value)
 def __str__(self):
 return "{}\n=====\n{}\nValue: {}\nDamage: {}".format(self.name, self.damage, self.desc, self.usable, self.value)
class BrokenSword(Weapon):
 def __init__(self):
 super(Weapon, self).__init__(name="Broken Sword",
 desc="A sword that didn't resist time.",
 value=1,
 usable=0,
 damage=1)

PyCharm states that desc, name, usable and value in the Weapon class (inside super().__init__()) are unsolved references, and that they are unexpected arguments in the BrokenSword(Weapon) class. The code is very similar to the tutorial one, so what is wrong with it? Was the tutorial written in python 2.x? How can I fix my code?

asked Oct 27, 2017 at 14:02

1 Answer 1

1

The Weapon class doesn't know what those arguments are. You have to define them either locally or -god forbid- globally. So Weapon.__init__ should accept arguments:

class Weapon(Item):
 def __init__(self, desc, name, usable, value, damage):
 super().__init__(
 desc=desc,
 name=name,
 usable=usable,
 value=value
 )
 self.damage = damage
answered Oct 27, 2017 at 14:07
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.