475 posts
Posted 02 November 2012 - 04:36 PM
Hi everyone! :D/>/>
I'm making a program and I need it to only do os.pullEvent() for a certain amount of time (2 seconds). Is there anyway to do this considering os.pullEvent freezes the computer until an event occurs? Thanks
839 posts
Location
England
Posted 02 November 2012 - 04:39 PM
If you do os.startTimer() beforehand, the os.pullEvent() will grab the timer event after that set time period if no events are sent before the timer event fires.
So:
local eventtocatch = 'key' --(for example)
local timeout = os.startTimer(2)
local e,arg1,arg2,arg3 = os.pullEvent()
if e=='timer' and arg1==timeout then
--time up
elseif e==eventtocatch then
--execute other code
end
475 posts
Posted 02 November 2012 - 05:00 PM
If you do os.startTimer() beforehand, the os.pullEvent() will grab the timer event after that set time period if no events are sent before the timer event fires.
So:
local eventtocatch = 'key' --(for example)
local timeout = os.startTimer(2)
local e,arg1,arg2,arg3 = os.pullEvent()
if e=='timer' and arg1==timeout then
--time up
elseif e==eventtocatch then
--execute other code
end
Thank you very much! This was simpler than I thought ^-^
839 posts
Location
England
Posted 03 November 2012 - 08:36 PM
You're welcome. I've recently been working quite closely with os.pullEvent so this was something I practically jumped on lol