interupting a repeat loop
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- Posts: 137
- Joined: Thu Jul 24, 2008 11:22 pm
interupting a repeat loop
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.
-
- VIP Livecode Opensource Backer
- Posts: 977
- Joined: Sat Apr 08, 2006 7:47 am
- Contact:
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
3. Name the second button "Stop" and set its script to:
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.
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
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
HTH,
Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com
www.quartam.com