Jump to content




Pulling an event for a certain amount of time


  • You cannot reply to this topic
3 replies to this topic

#1 lieudusty

  • Members
  • 419 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

#2 Pharap

  • Members
  • 816 posts
  • LocationEngland

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


#3 lieudusty

  • Members
  • 419 posts

Posted 02 November 2012 - 05:00 PM

View PostPharap, 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:
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 ^-^

#4 Pharap

  • Members
  • 816 posts
  • LocationEngland

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





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users