Date: Wed, 7 Dec 1994 14:51:58 EST From: John Dowdell <71333.42@COMPUSERVE.COM> Subject: Re: mouse click -> exit repeat?Lucky Kelley writes on 12/5 of events being blocked during execution of Lingo "repeat" loops.
Yes, this is what it's designed to do -- Lingo repeat loops are written for fastest logical processing, and in achieving this they will purposely not poll for system events... they'll just run, and run, and run, to get done with their calculations as quickly as possible.
Very long loops run the danger of locking the user out of the system. There are secondary issues with queued events, too, if operation is tied up into very long loops.
Best bet generally is to loop within a frame, instead of within a script. A "go the frame" allows for natural processing of all events within each cycle. No problems with flushing, either.
If absolutely required, you can put an "if the mouseDown then exit" within the repeat loop, but as there would still be secondary issues to handle, it's not as clean as using inclusive rather than exclusive loops.
Some developers use a hybrid approach... for instance, if you have to iterate something 10K times, then a Frame Script something like the following could be used:
on exitFrame
global counter
set counter = counter + 1
if counter > 100 then go the frame + 1
repeat with i = 1 to 100
-- do stuff
end repeat
go the frame
end exitFrame
This means we're only looping 100 iterations before allowing user and system
events to be processed... it doesn't kill user interaction, doesn't lock the
system as tightly... is preferable to playing within a tight loop.
Regards,
John Dowdell
Macromedia Tech Support
Date: Thu, 8 Dec 1994 02:42:27 +0000 From: Matthew Caldwell <sexkittn@BURN.DEMON.CO.UK> Subject: Re: mouse click -> exit repeat??? >I would like to allow the user to bail out of a repeat loop by clicking on a >sprite. ClickOn tests don't work within repeat loops, although rollOvers do. >Is there a way to do this? > >I'm thinking of using recursion. Is that allowed in Director? Will it work? > >I guess I could put my routine in a score script and conditionally "go to the >frame" until done. Is this preferable?Probably the last is the simplest. If you give the frame a score script of:
on exitFrame
tiddlyPom
go the frame
end exitFrame
where tiddlyPom is a handler or script fragment that performs a single
iteration of your loop, and then give your button a sprite script of:
on mouseUp
go the frame + 1
end mouseUp
that should do most of the trick. Each time you loop back on the frame you
give Director a little breathing space in which to handle events (such as
mouseClicks) and other housekeeping that it doesn't get an opportunity for
while it's actually running your script.
Recursion is possible, but doesn't sound like a sensible option in this case because of its expanding memory requirements - if the loop goes on a long time it could hang Director. Also, it probably wouldn't do what you want, since event handling would still be delayed while your script processes.
If you really want to use a repeat loop, you'll have to explicitly check for the mouseDown/Up during your loop, and check *where* it is (ie, if the mouseV & mouseH are within the region of your bail out button).
____ \ / Matthew Caldwell <sexkittn@burn.demon.co.uk> \/ Foux! there to eat lemons, axe gravy soup.