interupting a repeat loop

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Glenn Boyce
Posts: 137
Joined: Thu Jul 24, 2008 11:22 pm

interupting a repeat loop

Post by Glenn Boyce » Mon May 04, 2009 3:18 am

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.

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Contact:

Post by Janschenkel » Mon May 04, 2009 5:58 am

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.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

Glenn Boyce
Posts: 137
Joined: Thu Jul 24, 2008 11:22 pm

Post by Glenn Boyce » Tue May 05, 2009 11:10 pm

Thanks Jan. I'll give it a try

Post Reply