Reputation: 3
I get this error "local member event referenced before assignment" in the following code.
for event in event.get():
if event.type == QUIT:
sys.exit
I even tried added global event
before the beginning of for loop but then I'll get an error saying "event member not defined".
Can anybody please help me with this ?
Upvotes: 0
Views: 55
Reputation: 7753
See this example from the pygame docs:
import random, time, pygame, sys
from pygame.locals import *
...
for event in pygame.event.get():
if event.type == QUIT: #event is quit
terminate()
I'm guessing the problem is that you've imported pygame.event, so you're getting a name conflict. Change your import to just import pygame (and use the qualified reference pygame.event
) or else, as suggested, use a different name for your iterator variable.
Upvotes: 1