PDA

View Full Version : Delay Timer Function



jwilson56
November 15th, 2008, 08:39 PM
Well one function I use a lot is a delay timer. Nice thing is it will not hold up anything waiting around for a delay. Basic structure I use is as follows:

-- myDED and delayedFunc are any names you want

local function delayedFunc ()

-- This function will execute 60 seconds after so
-- do what you want after the delay here

end

-- do what you want before the delay here

Voice:Speak('This will play first and then after 60 seconds the other function will run')

-- kills any current delay timer... basically resets the delay

if myDED then -- kills an existing dispatcher
myDED:Close ()
myDED = nil
end

-- time is milliseconds so this would be 1 minute

-- setup new delay function. It will execute the 'delayedFunc' in 60 seconds

myDED = Classes.DelayedExecutionDispatcher:New (60000,delayedFunc)

sirbooker
November 16th, 2008, 04:44 PM
Hi John

i was wondering if you can make this trigger something at say the
40 sec mark then the 30 sec mark of the count down

paul

jwilson56
November 16th, 2008, 05:11 PM
Well you could always just create different delayed functions. I don't think you have any way of reading the remaining time left on the timer. One thing I do for my motion sensor delayed light turn off is to setup a delay then when the delay ends check to see if there is still motion by reading the 'not ready' status of the Elk motion sensor and if its still 'violated' then just reset the delay again. Your not limited to a single delay timer so just use your imagination.