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
Pulling an event for a certain amount of time
Started by lieudusty, Nov 02 2012 04:36 PM
3 replies to this topic
#1
Posted 02 November 2012 - 04:36 PM
Hi everyone!
/>
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
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
#2
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:
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
#3
Posted 02 November 2012 - 05:00 PM
Pharap, on 02 November 2012 - 04:39 PM, said:
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:
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
#4
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
2 user(s) are reading this topic
0 members, 2 guests, 0 anonymous users











