• Advertisement
Sign in to follow this  

How to pause a while loop in python

This topic is 1931 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I would like to know how to pause a while loop in python. Right now i am using :
[source lang="python"]raw_input("-->")[/source]
This method works, but this requires them to hit enter in the command prompt window that is open with the program. I was wanting them to just be able to hit enter and cycle through the loop with the game window selected. After several searches on google i came here because the only help with this issue was using the raw_input() functions.

Heres my while loop currently:
[source lang="python"]#Game loop

while game:
x = random.randint(1, 10)

DISPLAY.blit(gbg, (0, 0))

#the pplrty determiner
if x == 1:
p += 2
if x == 2:
p -= 2
if x == 3:
p += 3
if x == 4:
p -= 3
if x == 5:
p += 5
if x == 6:
p -= 5
if x == 7:
p += 3
if x == 8:
p -= 5
if x == 9:
p += 0
if x == 10:
p += 0

if p >= 50 and p < 60:
DISPLAY.blit(pplrty_decent, (225, 400))

elif p >= 60 and p < 85:
DISPLAY.blit(pplrty_good, (255, 400))
elif p >= 85 and p < 100:
DISPLAY.blit(pplrty_great, (255, 400))
elif p >= 25 and p < 50:
DISPLAY.blit(pplrty_bad, (225, 400))
elif p < 25:
DISPLAY.blit(pplrty_awful, (225, 400))


for event in pygame.event.get():

if event.type == QUIT:
pygame.quit()
sys.exit()
raw_input('-->')
pygame.display.update()

[/source]

Share this post


Link to post
Share on other sites
Advertisement
You'll need to use the pygame keyboard functions to wait for a keypress instead of using raw_input. raw_input is only for the terminal, which you may not have, or may not use, when you have a Pygame window open.

Alternatively, you can keep your game loop spinning and just not update any objects. You might want to consider writing some functions.

Share this post


Link to post
Share on other sites
You'll need to use the pygame keyboard functions to wait for a keypress instead of using raw_input. raw_input is only for the terminal, which you may not have, or may not use, when you have a Pygame window open.

Alternatively, you can keep your game loop spinning and just not update any objects. You might want to consider writing some functions.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement