[REQUEST] Wait for keypress or time
LoganDark 25 Apr 2016
I'd like a function that waits for a user to press a key, but after a specific amount of seconds, if the user hasn't pressed a key (it should skip instantly if you do) it skips automatically. Is that possible?
I have good knowledge with CC Lua, so feel free to explain it as technical as you want.
Edited by LoganDark, 25 April 2016 - 07:35 PM.
masterdisasterHD 25 Apr 2016
try this:
Edited by masterdisasterHD, 25 April 2016 - 07:39 PM.
local timeout = 3 function ontimer() sleep(timeout) end function onkey() os.pullEvent('key') end parallel.waitForAny(ontimer, onkey) --This waits for either of the 2 functions to finish before continuing --Further processing below this line
Edited by masterdisasterHD, 25 April 2016 - 07:39 PM.
LoganDark 25 Apr 2016
masterdisasterHD, on 25 April 2016 - 07:37 PM, said:
try this:
local timeout = 3 function ontimer() sleep(timeout) end function onkey() os.pullEvent('key') end parallel.waitForAny(ontimer, onkey) --This waits for either of the 2 functions to finish before continuing --Further processing below this line
Thanks!
LDDestroier 25 Apr 2016
I actually made the help screen of my QuickDraw game so that it slowly prints the help text, but if you press a button, it instantly displays the text. It's neato
LoganDark 25 Apr 2016
LoganDark 25 Apr 2016
Lupus590 26 Apr 2016
Edited by Lupus590, 26 April 2016 - 11:33 AM.
Bomb Bloke 26 Apr 2016
Other users are usually encouraged to make their own threads, but it's indeed recommended for posters to keep all their questions about a given project in the one place.
In any case, there's seldom good reason to actually lock a thread. It's a fairly heavy-handed way of saying "drop this subject".
In any case, there's seldom good reason to actually lock a thread. It's a fairly heavy-handed way of saying "drop this subject".