Reputation: 135
I've been following along with a bouncing ball example just to get my chops warmed up with pygame: every time I test my code I have to kill the game window by causing it to freeze, though in my code (taken directly from the pygame website) I state that the game should exit if the Escape key is pressed or the X button on the screen. I get an error
running == False
NameError: name 'running' is not defined
my code is
while 1:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running == False
if event.type ==pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
running == False
can I define "running?" such that the game doesn't simply freeze when I try to quit.
Upvotes: 1
Views: 1334
Reputation: 6433
First off, you should define running to True (running = True
) above your while loop. Secondly, you should be checking that value somewhere; easiest is to change while 1
to while running
Third, == is checking for equality, = is setting a value. You want to check event.type to be pygame.QUIT or KEYDOWN, so those == are correct, but then you want to set running to False, which is running = False
. Doing running == False as a statement is not effective.
Upvotes: 2