Newbie - Timers and Send
Dar Scott
dsc at swcp.com
Mon Dec 8 23:08:24 EST 2003
On Monday, December 8, 2003, at 03:42 PM, erik hansen wrote:
>> Always go to the clock for accurate
>> timing. adjust the
>> delay specified in the
>> send to target the end of the next period.
>
> would you have a short example handy?
I looked into the "Primer on Message Mechanics" stack available at my
web site, but it did not have a complete example. (See pages on Simple
Sync, Synchronization and Scheduling for partial info.)
It did mention an intermediate method that I forgot to mention. In
many cases you can get much better results by putting the send at the
top of the handler that is executed repeated rather than at the bottom.
There are advantages to putting it at the bottom, but if a better
timing cycle is desired, the top is better. This does not apply to the
example below.
I don't have a short example, but I'll make it up.
This is a variation of "Flasher with Abort and Init" in the "Primer on
Message Mechanics". It is untested, so let me know how it works and I
might put it in the next primer. It needs this script in the script of
a graphic (say a circle) and buttons to send initFlashing,
startFlashing and stopFlashing to the graphic.
*******************************************************
constant unlitColor = "100,130,110"
constant litColor = "255,0,0"
local flashID = ""
local currentColor = "100,130,110"
local flashTimer = ""
on initFlashing
stopFlashing
setColor unlitColor
end initFlashing
on startFlashing
if flashID is empty then
send "flash" to me in 0 seconds
put the result into flashID
put the long seconds into flashTimer -- new
end if
end startFlashing
on stopFlashing
cancel flashID
put empty into flashID
end stopFlashing
on flash
toggleColor
add .4 to flashTimer -- new
send "flash" to me in (flashTimer - the long seconds) seconds --
mod
put the result into flashID
end flash
on toggleColor
if currentColor is litColor then
setColor unlitColor
else
setColor litColor
end if
end toggleColor
on setColor theColor
set the backgroundColor of me to theColor
put theColor into currentColor
end setColor
******************************
Note that in this case, the send is at the end.
Dar Scott
More information about the use-livecode
mailing list