stopping an on-screen timer

Richard Gaskin ambassador at fourthworld.com
Thu Jan 19 18:00:46 EST 2006


Peter T. Evensen wrote:
> What is the best way to display a timer on the screen and then have it 
> stoppable?
> 
> Something like the following would work for the timer
> 
> on UpdateTimer
>   -- update the display
>   send UpdateTimer to me in 1 sec
> end UpdateTimer
> 
> My question is how best to stop the timer?
> 
> Is it better to look for the UpdateTimer message in the pendingMessages 
> and cancel it?
> Have a global variable indicating the timer is active and only send the 
> UpdateTimer to me if it is active?

What triggers the stop?

If it's a button, you could use a global easily enough:

on mouseUp
   global gTimerActive
   put false into gTimerActive
end mouseUp

on UpdateTimer
   global gTimerActive
   --
   -- update the display
   --
   -- also added a safety check here on the odd chance that
   -- this routine is called more than once between updates;
   -- with a one-second interval it's probably not needed,
   -- but with short intervals it can be handy, and does no
   -- harm if it's not needed:
   if gTimerActive is not "false" \
    AND "UpdateTimer" is not in the pendingMessages then
      send "UpdateTimer" to me in 1 sec
   end if
end UpdateTimer


-- 
  Richard Gaskin
  Fourth World Media Corporation
  ___________________________________________________________
  Ambassador at FourthWorld.com       http://www.FourthWorld.com



More information about the use-livecode mailing list