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
1 Answer 1
You have a global variable "creature" which is hiding your class.
guilds.pyaround where the exception is thrown? Can you printself, pos, namejust before the call to the ctor.