Timer

Phil Davis phildavis at attbi.com
Fri Dec 14 16:39:01 EST 2001


Hi Dominique,

> I want to rewrite a little timer I had in HC -- without resorting to
> "wait" or "idle" which are not recommended in MC...
>
> So, I have a button which starts the timer, and a numeric field which
> the seconds remaining.
> My goal is to show the seconds, for instance from 10 down to 0.
>
> I wrote a loop handler in the button:
>
> put 10 into field "temps"
> repeat 10 times
>    send "mouseup" to field "temps" in 1 second
> end repeat
>
> The field script:
>
> on mouseup
>    subtract 1 from me
> end mouseup
>
> The problem: it seems that the loop send all the commands at once,
> and doesn't "wait" for the 1 second delay...

Here's an explanation of your experience:
Nothing kept the "repeat" from executing as fast as it can. All the
"sent" messages are enqueued in "the pendingMessages" queue right away,
each with a one-second delay. After they are enqueued, you experienced a
one-second (approx) delay before the first one was released, right? Then
the second, and third, and the others were released microseconds after
the first one, with no noticable time between them.

So the problem was that all the sent messages had practically the same
release time.

To accomplish your goal without using "wait", and using your existing
approach, you could give each sent message a different release time,
like this:

   put 10 into field "temps"
   repeat with x = 1 to 10
     send "mouseup" to field "temps" in x seconds
   end repeat

The "repeat" would finish quickly as before, but the "mouseUps" would
each be released at the correct intervals.

Maybe this helps explain what you experienced.

Regards,
Phil

> --
> Regards,
> Dominique
> _______________________________________________
> metacard mailing list
> metacard at lists.runrev.com
> http://lists.runrev.com/mailman/listinfo/metacard





More information about the metacard mailing list