Interrupting a loop

Brian Yennie briany at qldlearning.com
Tue Feb 17 19:02:26 EST 2004


A couple of different approaches:

1. Keep a "state" variable between handlers, something like:

repeat forever
    put 1 into gameState
    doSomething
    put 2 into gameState
    doSomethingElse
    put 3 into gameState
    doSomethingMore
end repeat

Then you could use the state variable to resume action at the correct 
spot in your code, by expanding to something like:

if (not wasPaused) then put 0 into gameState
put TRUE into firstTime
repeat forever
    if (gameState >= 1) OR (not firstTime) then
      put 1 into gameState
      doSomething
    end if
    if (gameState >= 2)  OR (not firstTime) then
      put 2 into gameState
      doSomethingElse
    end if
    if (gameState >= 3)  OR (not firstTime) then
      put 3 into gameState
      doSomethingMore
    end if
    put FALSE into firstTime
end repeat


2. Check out "wait with messages", and see if this gets you enough 
interaction when paused:

repeat forever
    if (isPaused) then
        wait 100 milliseconds with messages
    else
        ...
    end if
end repeat

HTH,
Brian

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



More information about the use-livecode mailing list