+ 1

Disabling input() before prompt?

Hi all, I’m writing a text adventure using Python. Very often I use input() to accept input from the player to allow them to do anything in the game. Before the input() prompt, though, while a time.sleep() is running, the user is able to type and affect the text, and what they type is later accepted as the input. I need to disable this, to make the game smoother. Any help? Example: Print(“Do you want to go inside?”) Time.sleep(1) ans = input() if ans == “yes”: Etc If the user presses the enter key twice while the time.sleep() is occurring, the input will take those two blank enter keys as the input. I don’t want the user to be able to type anything until the input() is being run.

4th May 2020, 11:36 PM
Joel
4 Respuestas
+ 1
Flush the input buffer before accepting input. I don't know how to do it in python. In C we can do this. I guess there will be something in python too. This link may give you some ideas. https://stackoverflow.com/questions/2520893/how-to-flush-the-input-stream-in-python
5th May 2020, 12:21 AM
Peter Parker
Peter Parker - avatar
0
Hari Shankar thank you!! i will try this.
5th May 2020, 12:40 AM
Joel
0
I’m still having troubles with this. I cant seem to make it work. I use Windows 10. I think a simpler way to phrase this question is this: how do I make python ignore the enter key until input() actually appears?
5th May 2020, 7:44 PM
Joel
0
Can you post your code here?
5th May 2020, 11:28 PM
Peter Parker
Peter Parker - avatar