Python Forum
Thread Rating:
  • 2 Vote(s) - 3.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
RPG game trouble
#3
Thanks Craig. I added an argument to each function, and that did the trick.

I'm now having trouble with the instantiation of the objects.

Initially, I got the following error:

Traceback (most recent call last):
 File "drank_game.py", line 142, in <module>
   player = Hero()
 File "drank_game.py", line 12, in __init__
   super().__init__(name=player_name, health=3)
TypeError: super() takes at least 1 argument (0 given)

I did a little research, and am I right in thinking that the use of super() without arguments is only for Python3? I'm using Python 2.

If so, I tried changing it up:

class Character(object):
   def __init__(self, name, health):
       self.name = ""
       self.health = health

class Hero(Character):
   def __init__(self):
       super(name=player_name, health=3).__init__()
This gave me an error that player_name is not defined, which makes sense. What would be the cleanest way to setup the child class Hero to inherit from the parent Character using the super? Or, is using super in this case redundant? I'm trying to have it so the 'name' attribute is the same as the 'player_name' variable defined within the intro function.
Reply


Messages In This Thread
RPG game trouble - by J125 - Apr-08-2017, 05:38 PM
RE: RPG game trouble - by ichabod801 - Apr-08-2017, 06:04 PM
RE: RPG game trouble - by J125 - Apr-17-2017, 11:43 AM
RE: RPG game trouble - by ichabod801 - Apr-18-2017, 01:20 AM
RE: RPG game trouble - by J125 - Apr-20-2017, 10:25 AM
RE: RPG game trouble - by Kebap - Apr-20-2017, 05:21 PM
RE: RPG game trouble - by J125 - Apr-24-2017, 11:38 AM
RE: RPG game trouble - by nilamo - Apr-29-2017, 04:42 PM
RE: RPG game trouble - by J125 - May-03-2017, 08:34 AM

Forum Jump:

User Panel Messages

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