Avoiding mouse polls

Dar Scott dsc at swcp.com
Sat Dec 14 23:16:01 EST 2002

On Saturday, December 14, 2002, at 08:44 PM, David Vaughan wrote:

> Do **not** use repeat. Use "send in N seconds" to repeat the message. 
> See Cubist's code and our other descriptions.

He's right, Ken.

If you can't bring yourself to move to using "send", we can advise 
concerning "wait" options, but "send" is the way to go.

I'll put at the end of this mail a simple exercise using "send".  It may 
help in understanding about send and you might be able to adapt it to 
your need.

Dar Scott

Here is an example for a flashing light.  It is a simplification of one 
of my first scripts using send.  I put this script in a circle graphic:
-- This is empty if flashing is off.
-- It is the id (for message cancelation) if on.
local flashingID

-- Modify this handler when adapting to other uses
on change
   if backgroundColor of me is red then
     set backgroundColor of me to green
     set backgroundColor of me to red
   end if
end change

on startFlashing
   -- don't start cycle if it is already going
   if flashingID is empty then cycle
end startFlashing

on cycle
   send cycle to me in 333 milliseconds
   put the result into flashingID
end cycle

on stopFlashing
   cancel flashingID  -- don't bother testing for empty
   put empty into flashingID
end stopFlashing

My "Start" button has this script:
on mouseUp
   send startFlashing to graphic "Flasher"
end mouseUp

The stop button has this script:
on mouseUp
   send stopFlashing to graphic "Flasher"
end mouseUp

More information about the Use-livecode mailing list