how to make things happen at specific times
J. Landman Gay
jacque at hyperactivesw.com
Wed Apr 8 16:45:23 EDT 2009
DunbarX at aol.com wrote:
> I need to understand how pending messages are stored.
>
> But going back to the stone age, I have several "alarms" running at all,
> er, times, and I have always used an "idle" handler to invoke them:
>
> on idle
> if the long time = "4:00:00 pm" then
> wait 100 -- as Sarah says, make sure this only happens once
> send yourMessage to whereEver
> end idle
>
> You could embellish this endlessly; case structures come to mind. I have
> several library stacks always running with such handlers in them, so it
> doesn't matter what working stacks might be open; the message is sent.
In general, idle handlers should be avoided. They take up lots of engine
time, and usually 99% of the time they execute, nothing happens.
Instead, Rev offers the "send <someMessage> in <time>" command that lets
you place messages in a queue, where they will execute at the time you
indicate. You can check this queue by looking at the pendingMessages
property, which is also available in its respective message box pane. By
placing an event in the queue, the engine isn't tied up needlessly by
constantly checking for something that usually doesn't have to happen.
In the example above, you could schedule a single event to take place
every day at 4 PM. Basically you'd calculate the number of seconds until
the next alarm time, and then queue the message to trigger at that time:
function getNextDueTime
get the date && "4:00 PM"
convert it to dateitems
add 1 to item 3 of it
convert it to seconds
return it - the seconds
end getNextDueTime
and in an alarm handler:
-- do alarm stuff, then retrigger next event:
send "myAlarm" to me in getNextDueTime() seconds
When the alarm goes off, your handler calculates the next due time and
inserts the new message into the pending event queue.
Pending messages are not saved between sessions, so you'll have to
reload any permanent alarms on each launch.
--
Jacqueline Landman Gay | jacque at hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
More information about the use-livecode
mailing list