Interrupting a loop

Graham Samuel graham.samuel at wanadoo.fr
Tue Feb 17 18:48:50 EST 2004


Folks, maybe this is obvious and I'm too tired to see it, but what would be 
a good approach to the following problem?

In the app I'm developing have a kind of animated simulation which consists 
of 'repeat forever' loop that causes a series of actions (animations, 
sounds etc) to take place on the screen. The details don't matter, but the 
loop calls a lot of handlers in succession - some of which are quite 
complex - until it detects a particular condition and then it stops. A 
'run' like this can go on for several minutes.

What I want is to provide the user with a 'pause' button, which stops the 
looping action at the end of the last handler to be run (so the handlers 
called from within the repeat loop are kind of atomic in this context), and 
also provide a 'resume' button that gets things started where they left 
off. During the pause, the user is allowed to click various things on the 
screen etc and cause other handlers to run - so it's not just a case of 
freezing everything.

I can't immediately see an obvious way to do this, apart from getting the 
mouseUp event in the 'pause' button to set a flag and then test the flag at 
each step of the repeat loop (i.e. between each handler call). Given that 
the RR engine provides a very sophisticated message handling structure, 
this seems very primitive; and even if I do have this approach, I'm not 
sure how to handle the temporary exit from the repeat loop so as to be able 
to come back to it when 'resume' is triggered.

I'd be grateful for any ideas.

TIA

Graham

---------------------------------------------------
Graham Samuel / The Living Fossil Co. / UK & France  




More information about the use-livecode mailing list