Is there a way of making an 'Repeat until input'?
I'm making a game in python and I'm aiming for a title screen similar to the original Super Mario Bros I know how to make the "press enter to start" flash but I can't figure out a way for it to do this until the player presses the enter button. Is there a way of doing this?
Oh, by the way...
import os # just imports the base os module, should work in repl.it
os.system("""bash -c 'read -s -n 1 -p "Press any key to continue..."'""") # this makes it so that it won't proceed until ANY key is pressed... you can change the string to whatever you want, but i'm still looking into non-static methods for this
Could you be a little more descriptive?
Are you using pygame or just inputs from the python shell?
(i'm assuming pygame)
If it's pygame you're using, try the following:
while not start:
# (everything in loop here)
for event in pygame.event.get(): if event.type == pygame.KEYDOWN: # checks if key pressed start=True # once this happens, the loop is broken
feel free to copy this, but this is really dumb and simple...
The way to see if a keyboard key was pressed is [event.type == pygame.KEYDOWN]. It says False or True as it's output, so you can easily implement it in your program.
Keep in mind 'pygame.event.get()' is a list of events, and it contains all inputs/events that are given, that's why you need a for loop to check each event, and if one of them is a key pressed event (using event.type... there are other values like event.key which specifies which key was pressed, but it's not needed for this)
All you need is a while loop that depends on the condition of a variable, for convenience let's call it enterPressed. You don't have to actually call it that obviously. Anyway, the while loop is going to compare the value of the enter key, and when it finds it as pressed, then change the enterPressed variable to true. If your while loop looks like this: while not enterPressed then it should work.