Python Forum

Full Version: Beginner in pygame, I don't know how to use events
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi everyone,I'm a beginner with pygame. I wanted to use events and look on internet how to use them but the problem is that python keep telling me "NameError: name 'event' is not defined". I don't understand why, all websites I've seen used event like this. Can somebody help me please ? Smile

if event.type == KEYDOWN:
print ("changer de lieu")
That code is presented within a for loop of events.

for event in pygame.event.get():
   if event.type == KEYDOWN:
       ...
(Jan-19-2018, 12:37 PM)metulburr Wrote: [ -> ]That code is presented within a for loop of events.
for event in pygame.event.get(): if event.type == KEYDOWN: ...
Thank's a lot ! I have no more error message :) but when I write nothing happens, I don't get it Huh

for event in pygame.event.get():
if event.type == KEYDOWN:
print ("...")
(Jan-26-2018, 01:35 PM)Erepiv1 Wrote: [ -> ]Thank's a lot ! I have no more error message :) but when I write nothing happens, I don't get it
(Jan-19-2018, 12:37 PM)metulburr Wrote: [ -> ]That code is presented within a for loop of events.

for event in pygame.event.get():
   if event.type == KEYDOWN:
       ...


... was just for whatever you want to put to execute. Its going to run, but not do anything. If you put print('something') instead of ... then you would see something every time you press a key.
(Jan-26-2018, 01:37 PM)metulburr Wrote: [ -> ]
(Jan-26-2018, 01:35 PM)Erepiv1 Wrote: [ -> ]Thank's a lot ! I have no more error message :) but when I write nothing happens, I don't get it
(Jan-19-2018, 12:37 PM)metulburr Wrote: [ -> ]That code is presented within a for loop of events.
for event in pygame.event.get(): if event.type == KEYDOWN: ...
... was just for whatever you want to put to execute. Its going to run, but not do anything. If you put print('something') instead of ... then you would see something every time you press a key.

I see , but when I try, nothing appears :/
did you change ... to print something instead?