Time Field (Please Help)
Jacqueline Landman Gay
jacque at hyperactivesw.com
Mon Mar 4 21:57:01 EST 2002
On Monday, March 4, 2002, at 05:47 PM, Rob Cozens <rcozens at pon.net> wrote:
> Once the original handler runs once, will it continue to send an
> updateTime message every second until the RR engine quits regardless of
> what card or stack is in the current window?
It will continue to send as long as "updateTime" continues to run without
an error. A script only needs to trigger it once from somewhere (probably
opencard) to get the loop going, and at any given time there will only be
one outstanding message. Once another handler cancels the outstanding
message, everything stops.
I'd probably do it something like this in a card or stack script:
on openCard
send "updateTime" to me -- this gets the messages started
end openCard
on updateTime
put the long time into fld "now"
-- next line keeps the loop going; there is never
-- move than one message in the queue at a time
-- because the one that activated this handler is
-- used up now, and the only other one is the one
-- we are about to send next:
send "updateTime" to me in 1 second
end updateTime
on closeCard -- this stops the messages
repeat for each line L in the pendingMessages
if L contains "updateTime" then cancel (item 1 of L)
end repeat
end closeCard
I like the repeat loop scan instead of tracking the id in a global. The
scan is very fast, and it's one less global to worry about.
If the script doesn't cancel the pending messages, then yes, the messages
will keep going until the app quits or there is an error. In this case, if
a user moves to another card without a field named "now", there would
probably be an error when the updateTime handler tries to access a field
that no longer exists on the card. The error would occur before the next
"updateTime" message gets sent, effectively stopping the loop.
--
Jacqueline Landman Gay | jacque at hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
More information about the use-livecode
mailing list