0
votes

I'm trying to make a script that will prompt the user and wait for them to press a key indicating the answer, or if no key is pressed for a fixed amount of time choose the default option.

Sadly, I'm doing this in an environment with lua embedded into it, so I cannot add libraries or modify the source. Also io.read blocks until the user presses enter and io.popen is not available.

Is it possible to do this?

P.S. I need this for a game where something is happening by time, proceeding in stages, and you need to decide when to take action without much time to think about it. If you can think of another way to do this, please tell me.

1
It's not possible to know how to do this without knowing something about the environment in which your Lua is being embedded. You seem to have access to certain standard Lua libraries. Are you able to load external libraries (via require and so forth)? - Nicol Bolas
@NicolBolas I tried, but all ones included in the environment are loaded by default. - RPFeltz

1 Answers

1
votes

wait for them to press a key [..] II cannot add libraries or modify the source [..] io.read blocks until the user presses enter [..] Is it possible to do this?

No. Lua's IO libraries are based on C's IO libraries, which are all stream based. There's no way to detect keypresses. So, no, without extending Lua with native code (which you say you cannot do), this is not possible.