Most Efficient Timer?
Alex Tweedly
alex at tweedly.net
Mon Nov 29 14:08:56 EST 2004
At 13:33 29/11/2004 -0500, Frank D. Engel, Jr. wrote:
>This helps to avoid another problem as well. If a one-second timer is
>started at, say, 1:31:32, then the minute will be about half-over by the
>time the display is updated, so that the time display is only accurate
>about half of the time.
>
>Of course, the timer may drift somewhat if there is a delay in
>message-processing, depending on how it has been configured...
You can solve both of those problems by doing something like
send myTimer to me in (1000 - (the millisecs mod 1000) ) millisecs
OK - it looks ugly, but it should line you up onto the second boundaries
quite simply.
In fact, the following script (with the addition of the obvious scrolling
field, and a "Stop" button") shows that there is some systematic drift of
up to 8 milliseconds (on my very SLOW Win2000 laptop).
>global gStop
>
>on mouseUp
> put 0 into gStop
> put empty into field "Field"
> send myTimer
>end mouseUp
>
>on myTimer
> put (the millisecs mod 1000) into t
> put t & TAB & the secs & TAB & the millisecs & cr after field "Field"
> if gStop = 0 then
> send myTimer to me in (999 - (the millisecs mod 1000) ) millisecs
> end if
>end myTimer
-- Alex.
More information about the use-livecode
mailing list