![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: Feb 2005
Posts: 67
Rep Power: 4
![]() |
Class Problem 'Instance has no such attribute'
class Hero:
def He_Stats(self):
self.Hero_stats = {'hp':[10,10,0,100],'attack':[7,0,100],'defense':[6,0,100], 'initiative':[2,0,100]}
class Enemy:
def En_Stats(self):
self.Enemy_stats = {'hp':[3,3],'attack':[3],'defense':[3],'initiative':[0]}
class Printer(Enemy, Hero):
def printer(self):
en_stats = self.En_stats
he_stats = self.He_stats
print en_stats
print he_stats
x = Printer()
x.printerThis is the code of a small rpg battle system i started to code... But when i try to run it, it give me the message, that the Printer instance has no He_stats and En_stats attribute... I just cannot get, what is wrong with this code... Any Ideas would be helpful!!! Thx a lot Fred |
|
|
|
|
|
#2 |
|
Programming Guru
![]() |
It works for me... But the last line is quite pointless, I think you forgot the () after the printer.
Edit: Then it that case you need to do: class Hero:
def He_Stats(self):
return {'hp':[10,10,0,100],'attack':[7,0,100],'defense':[6,0,100], 'initiative':[2,0,100]}
class Enemy:
def En_Stats(self):
return {'hp':[3,3],'attack':[3],'defense':[3],'initiative':[0]}
class Printer(Enemy, Hero):
def printer(self):
en_stats = En.En_stats()
he_stats = He.He_stats()
print en_stats
print he_stats
En = Enemy()
He = Hero()
x = Printer()
x.printer()That should do it. If they are all seperate classes, they all have to be declared.
__________________
Waterloo's Canadian Computing Competition (CCC) - Stage 2 Problems, Solutions, and Test Data Last edited by Sane; May 23rd, 2005 at 9:42 PM. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|