0

I'm making a game, and I have some problems... I have a function that loads a map (usually when the player collides with a gate). I have two gates and two maps (one gate on each map). When I walk to a gate the second map is loaded, when I walk through a gate on that map, the first map is loaded. I also have a tree on the first map. Everything works fine unless I click on that tree. This is very strange because I don't have anything that handles that! Nothing should happen! And actually, nothing happens, except when I try to get back from the second map it doesn't work!

This is the error message I keep getting:

Traceback (most recent call last):
File "guilds.py", line 820, in <module>
load_map(objekt.gate_path, objekt.name, False)
File "guilds.py", line 287, in load_map
npc(o[1], o[3])
File "guilds.py", line 147, in __init__
creature.__init__(self, pos, name)
TypeError: __init__() takes exactly 3 arguments (4 given)

So there seems to be a problem loading the NPCs from the map (NPC class inherits from the creature class).

HERE ARE THE TWO CLASSES:

a) NPC:

class npc(creature):
 def __init__(self, pos, name):
 self.move_target = crt.crt[name]['move_target']
 if 'quest' in crt.crt[name]:
 self.quest_name = crt.crt[name]['quest_name']
 self.move_quest = crt.crt[name]['move_quest']
 self.q_giver = True
 else:
 self.q_giver = False
 self.guild = crt.crt[name]['guild']
 lista_npc.append(self)
 creature.__init__(self, pos, name)

b) creature, which NPC inherits from:

class creature():
 def __init__(self, pos, name):
 self.pic = []
 self.lista_slika = crt.crt[name]['ls_slk']
 for slika in self.lista_slika:
 self.pic.append(pygame.image.load(slika).convert()) #load the image
 for slika in self.pic:
 self.colorkey = slika.get_at((0,0)) #get the colokey from the first pixel (0,0)
 slika.set_colorkey(self.colorkey, RLEACCEL)
 self.counter = int(time.time())
 self.time = int(time.time())
 self.pos = pos
 self.rect = self.pic[0].get_rect() #get image rectangle
 self.rect = self.rect.move(self.pos) #get the rectangle on the starting position
 self.current_health = crt.crt[name]['health']
 self.max_health = crt.crt[name]['health']
 self.name = name
 self.targeted = False
 self.targeted_3 = False
 lista_creature.append(self)
 def follow(self):
 if self.face == 0:
 self.rect = self.rect.move(NPCspeed_right)
 self.pos = (self.pos[0] + NPCspeed_right[0], self.pos[1] + NPCspeed_right[1])
 if self.face == 1: 
 self.rect = self.rect.move(NPCspeed_left)
 self.pos = (self.pos[0] + NPCspeed_left[0], self.pos[1] + NPCspeed_left[1])
 if self.face == 2: 
 self.rect = self.rect.move(NPCspeed_up)
 self.pos = (self.pos[0] + NPCspeed_up[0], self.pos[1] + NPCspeed_up[1])
 if self.face == 3: 
 self.rect = self.rect.move(NPCspeed_down)
 self.pos = (self.pos[0] + NPCspeed_down[0], self.pos[1] + NPCspeed_down[1])
 def die(self): 
 self.randin = random.randint(-100, 100)
 self.randin2 = random.randint(-100, 100)
 self.pos = (self.pos[0] + self.randin, self.pos[1] + self.randin2)
 self.combat = False
 self.current_health = self.max_health
 self.rect.move_ip(self.randin, self.randin2)
 self.targeted = False
 for quest in lista_quest:
 if quest.target_name == self.name and quest.onit == True:
 quest.goal -= 1
asked Mar 27, 2011 at 17:19
3
  • Can you post some code from guilds.py around where the exception is thrown? Can you print self, pos, name just before the call to the ctor. Commented Mar 27, 2011 at 17:27
  • The code you pasted looks good, are you sure that's all and the right code? Which lines are marked in the traceback? Commented Mar 27, 2011 at 17:29
  • Actually I'm not sure, I thought it was something in this code... Strange, could you contact me so I can send you some more code? [email protected] Commented Mar 27, 2011 at 17:34

1 Answer 1

2

You have a global variable "creature" which is hiding your class.

answered Mar 27, 2011 at 17:41
Sign up to request clarification or add additional context in comments.

6 Comments

In which class? I don't see it... Contact me on [email protected] please :)
Nevermind, +1. @Yann: You propably have a global variable defined as creature = creature() - it's not in the code you showed us, so we can't tell you where. Class names should be upper-case by the way, partially to avoid this problem.
I love you man! It was true! There is a list of all the creatures, and I did this: for creature in l_creature: So I changed the word 'creature' to 'crtr' and it works now! I'll start renaming my classes right away, if that's the standard. So the first letter should be upper case? And if it's more than one word then it's something like this ManBearPig? Thanks again!
@Yann: See python.org/dev/peps/pep-0008 for naming convention and other coding style guidelines.
@Yann: Hehe, glad to be of help. You have no idea how often that happened to me. Nowadays I name all my ClassesLikeThis (and none_of_the_variables). If there's a class (like "object") that isn't LikeThis, I start to feel uneasy ;-)
|

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.