General Question

iamnothuman's avatar

Python Code error?

Asked by iamnothuman (9points) November 10th, 2009
10 responses
“Great Question” (0points)

this is my code:
import pygame
from random import randint
from pygame.locals import *
screen_size=(840,840)

class enemy(pygame.sprite.Sprite):
def __init__ (self,x,y):
pygame.sprite.Sprite.__init__(self)
self.image=image_load(“enemy.jpg”)
self.rect=self.image.get_rect()
self.rect.centerx=x
self.rect.centery=y
def update(self, time_passed):
pass
def main():
hidden=False

enemy1=enemy((400,400))
screen=pygame.display.set_mode ((640,480))
pygame.display.set_caption(“Time Crisis!”)
clock=pygame.time.Clock()
background=pygame.surface.Surface(screen_size).convert()
cursor=pygame.image.load(“shooterdot.jpg”).convert()
background.fill((0,0,0))
pygame.init()
while True:
for event in pygame.event.get():
if event.type==QUIT:
exit()
screen.blit(background,(0,0))
x,y=pygame.mouse.get_pos()
x-=cursor.get_width()/2
y-=cursor.get_height()/2
screen.blit(cursor ,(x,y))
pygame.display.update()

if __name__ ==“__main__”:
main()

this is the error:
Traceback (most recent call last):
File “c:\Users\Owner\Documents\code\pyhton\shooter.py”, line 38, in <module>
main()
File “c:\Users\Owner\Documents\code\pyhton\shooter.py”, line 18, in main
enemy1=enemy((400,400))
TypeError: __init__() takes exactly 3 arguments (2 given)

help?

Topics: ,
Observing members: 0
Composing members: 0

Answers

Response moderated
Response moderated
andrew's avatar

You have too many parens in that line—you’re passing in a tuple instead of two integers.

iamnothuman's avatar

which line?

andrew's avatar

Your traceback tells you the answer:
File “c:\Users\Owner\Documents\code\pyhton\shooter.py”, line 18, in main
enemy1=enemy((400,400))

iamnothuman's avatar

Traceback (most recent call last):
File “C:\Users\Owner\Documents\code\pyhton\shooter.py”, line 38, in <module>
main()
File “C:\Users\Owner\Documents\code\pyhton\shooter.py”, line 18, in main
enemy1=enemy(400,400)
File “C:\Users\Owner\Documents\code\pyhton\shooter.py”, line 9, in __init__
self.image=image_load(“enemy.jpg”)
NameError: global name ‘image_load’ is not defined

thats what i get now

J0E's avatar

If I would be paying more attention in my Python class I could probably answer this…

J0E (13172points)“Great Answer” (0points)
ben's avatar

@iamnothuman that means python’s not finding the definition for image_load, which probably means you need to add a line which imports image_load at the top of the file.

Find where image_load is defined and then import it like:

from pygame import image_load (if that’s where image_load were defined…)

Grisaille's avatar

If Tim comments in this thread, the internet might implode.

Response moderated (Spam)

Answer this question

Login

or

Join

to answer.

Mobile | Desktop


Send Feedback   

`