239 posts
Location
Macintosh HD/Users/LoganDark
Posted 25 April 2016 - 08:34 PM
Are requests even allowed in this section?
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 on 25 April 2016 - 06:35 PM
126 posts
Location
The Netherlands
Posted 25 April 2016 - 08:37 PM
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
Edited on 25 April 2016 - 06:39 PM
239 posts
Location
Macintosh HD/Users/LoganDark
Posted 25 April 2016 - 08:40 PM
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!
1715 posts
Location
ACDC Town
Posted 25 April 2016 - 08:43 PM
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
239 posts
Location
Macintosh HD/Users/LoganDark
Posted 25 April 2016 - 08:45 PM
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
I just had to use parallel.waitForAny.
8543 posts
Posted 25 April 2016 - 10:25 PM
Moved to Ask a Pro.
239 posts
Location
Macintosh HD/Users/LoganDark
Posted 25 April 2016 - 11:31 PM
Moved to Ask a Pro.
Better to lock too, since my problem was solved. It also introduced me to parallel.waitForAny.
2427 posts
Location
UK
Posted 26 April 2016 - 09:37 AM
Ask a pro is usually not locked as it allows others with a similar problem to post additional questions
Edited on 26 April 2016 - 10:33 AM
7083 posts
Location
Tasmania (AU)
Posted 26 April 2016 - 09:47 AM
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".