Ask coding questions

← Back to all posts
User Input Question
HayIsForHorses

Okay, so what if I want to give the user a certain amount of time to give an input, or if something happens in-between that time it overrides it? I'm trying to make a game and I need it to implement this. I am in Python.
Is there any module that can help me with this?

Answered by Saml2020 [earned 5 cycles]
View Answer
Voters
HayIsForHorses
Comments
hotnewtop
Saml2020

Try the inputtimeout module. It seems to be the one you're looking for.

HayIsForHorses

@Saml2020 Heck yes. Thanks!

hanmbi

yeah
i also use python
you can use import time
and a if statement
and a for loop with range
for example:
listname = 0
inputname = ("would you run, fight or hide?" \n)
for x in range(1, 3000):
time.sleep(0.01)
listname = listname +1
if listname == 3000:
print("time's up! you dident choose something so you lost!")
else:
if inputname == "run":
print ("rtgbrg")
elif inputname == "fight":
print ("fgbfrg")
else:
print ("rgfbeg")
but thats just a example

hanmbi

no need to thank me

HayIsForHorses

@hanmbi that wouldn't work because the system would wait for the users input

hanmbi

@HayIsForHorses oh, sorry i just wanted to help

MrVoo

What would you use it for? There's probably some janky workaround

HayIsForHorses

@MrVoo I'll give an example.
So let's say something random is triggered to happen, but the system is waiting for user input.
I would want the input to cancel and then do the random thing.
It's like trying to run a while loop using input:

You see, the while loop wouldn't run unless the user gave input, and I want to stop that.
(Think of it like timing in a rhythm game sort-of.)

MrVoo

@HayIsForHorses You could try and use a thread with a timer, if it gets to zero and the input isnt given (the variable has no value) you lose

HayIsForHorses

@MrVoo okay, I'll look into that