Disabling input() before prompt? | Sololearn: Learn to code for FREE!

+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.

5/4/2020 11:36:34 PM

Joel

4 Answers

New Answer

+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

0

Hari Shankar thank you!! i will try this.

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?

0

Can you post your code here?