Avoiding mouse polls
Cubist at aol.com
Cubist at aol.com
Sat Dec 14 15:53:01 EST 2002
sez pixelbird at interisland.net:
> I have objects which hilite (not really, they just change pictures) in a
> sequencial loop. I want to choose one so I click when it's hilited and that
> causes further actions/choices.
> I can't see any way of doing this without polling for the click.
In MC/Rev, you can do something like this:
# in card script
local ListHilite,HiliteNumber,StackState
# "ListHilite" is a comma-delim. list of the items that get hilited
# "HiliteNumber" is the number of the list-item that was most recently hilited
# "StackState" contains a string which lets you control what's going on
on CycleHilite
HiliteOff (item HiliteNumber of ListHilite)
# "HiliteOff" is a separate handler that removes your non-standard
'hiliting'
put 1 + (HiliteNumber mod (the number of items in ListHilite)) into
HiliteNumber
HiliteOn (item HiliteNumber of ListHilite)
# "HiliteOn" is a separate handler that creates your non-standard 'hiliting'
if StackState = "idle" then send "CycleHilite" to me in 1 second
# "1 second" or however fast you want the hiliting to change from one item
to another
# note the use of StackState here
end CycleHilite
on mouseUp
do (item HiliteNumber of
"ScrollHorizRt,ScrollHorizLf,ScrollVertUp,ScrollVertDn")
# the items in this list are separate handlers
# each of these handlers should take care of (re-)setting the value of
StackState in an appropriate fashion
end mouseUp
This way, there's no mouse polling, as the stack waits patiently for the
user to click. When the user does click, the stack executes whatever handler
is associated with whatever thingie was hilited at the time; otherwise,
CycleHilite just chugs quietly along.
Hope this helps...
More information about the use-livecode
mailing list