Page 1 of 1

interupting a repeat loop

Posted: Mon May 04, 2009 3:18 am
by Glenn Boyce
I have a simple repeat loop that runs for some time. What can I do to interupt it? I want to have a stop button and have tried a couple of methods to get the loop to stop but once its going the stop button doesn't work.

Posted: Mon May 04, 2009 5:58 am
by Janschenkel
I made a stack with 2 buttons and a field to test this.
1. Name the field "Time"
2. Name the first button "Loop" and set its script to

Code: Select all

on mouseUp
   local tSeconds
   --
   put the seconds + 10 into tSeconds
   set the uStopped of me to false
   repeat while the seconds < tSeconds
      put the milliseconds into field "Time"
      wait 10 milliseconds with messages
      if the uStopped of me then
         put "<<<Stopped>>>" into field "Time"
         exit mouseUp
      end if
   end repeat
   put "<<<Finished>>>" into field "Time"
end mouseUp
3. Name the second button "Stop" and set its script to:

Code: Select all

on mouseUp
   answer "Are you sure you want to stop?" with "Stop" or "Continue"
   if it is "Stop" then set the uStopped of button "Loop" to true
end mouseUp
Now, when you click on the first button, the script will churn away for about ten seconds - but the wait 10 milliseconds with messages gives it just enough breathing room for the user to click on the 'Stop' button and interrupt the loop.

HTH,

Jan Schenkel.

Posted: Tue May 05, 2009 11:10 pm
by Glenn Boyce
Thanks Jan. I'll give it a try