python - What do? __init__() takes exactly 3 arguments (1 given)? -
this question has answer here:
here's error gives me along code lines specified. apologies past post.
traceback (most recent call last): file "h:\users\daniel\desktop\final project\gold hunter.py", line 352, in <module> main() file "h:\users\daniel\desktop\final project\gold hunter.py", line 346, in main score = game() file "h:\users\daniel\desktop\final project\gold hunter.py", line 195, in game pirate = pirate() typeerror: __init__() takes 3 arguments (1 given)
actual code
main() line 352 score = game() line 346 pirate = pirate() line 195
pirate constructor gives me error nameerror: global name 'dx' not defined
class pirate(pygame.sprite.sprite): east = 0 def __init__(self, screen, dx): self.screen = screen pygame.sprite.sprite.__init__(self) self.image = pygame.image.load("king_pirate/running e0000.bmp") self.image = self.image.convert() trancolor = self.image.get_at((1, 1)) self.image.set_colorkey(trancolor) self.rect = self.image.get_rect() self.rect.inflate_ip(-50, -30) self.rect.center = (0, random.randrange(30,450)) self.img = [] self.loadpics() self.frame = 0 self.delay = 4 self.pause = self.delay self.dx = dx
i agree lee's comment. cannot see class pirate:
constructor clear __init__
function taking 3 arguments when define it. these self, argument1, argument2
, when call pirate = pirate()
on line 195, must provide 2 arguments (it self
on own). need give argument1 , argument2 defined in constructor. post constructor more help. line 195 should pirate = pirate(argument1, argument2)
good luck!
Comments
Post a Comment