Page 1 of 1

exiting a long handler

Posted: Tue Jun 19, 2012 7:26 pm
by adventuresofgreg
Hi: I have a handler which controls a long sequence of animations, and I would like to be able to exit this handler (cancel it) from another script, anytime.

I can do it if I add: "if cancelme = 1 then exit animationHandler", but I have to place this line multiple times throughout the sequence in order to 'catch it' when I set the global cancelme to equal 1 from outside the animationHandler.

Is there a way in LiveCode to directly exit a handler from outside the handler without having to continuously look for a global setting?

Thanks,
greg

Re: exiting a long handler

Posted: Wed Jun 20, 2012 12:03 am
by jmburnod
Hi Greg,

Do you have a loop (by repeat) in your handler animationHandler ?
If yes you can try

Code: Select all

wait 10 milliseconds with messages
in the prev line of "if cancelme = 1 then exit animationHandler"

and "cancelme" should be a local or global variable

Code: Select all

local cancelme

on StartCount
   put 0 into cancelme
   repeat with i = 1 to 10000
      put i
      wait 10 milliseconds with messages
      if cancelme = 1 then exit StartCount
   end repeat
end StartCount

on stopCount
   put 1 into cancelme
end stopCount
Best regards

Jean-Marc

Re: exiting a long handler

Posted: Wed Jun 20, 2012 1:03 am
by adventuresofgreg
Thanks Jean-Marc

No, there is no loop in the long handler. It's a step by step list of instructions with arrows pointing to different things, and buttons being pressed, etc. Sort of like:

make this field slide in (with aemoveto animationEngine handlers)
wait 2 seconds
move a graphic of a hand to a button
click the button
move the hand away
move the field out
move a new field in
wait 5 seconds
etc, etc, etc

I need some way for the user to EXIT out of this long list of instructions. Currently the only way I can think of doing it is inserting "if global cancelme=1 then exit this handler" between each and every single line. It works, but it isn't very elegant, and won't work until the current "step" is completely finished.

greg

Re: exiting a long handler

Posted: Wed Jun 20, 2012 2:02 am
by dunbarx
I don't see a way out of checking for some sort of state as often as required. I just finished a project where several different running handlers were possible. I had to include a "check" all over the place, whether or not the mouse had been clicked in an "abort" button. I had the advantage of needing many fast repeat loops, so the checking was done constantly.

Inelegant is in the eye of the beholder. Peppering these things throughout your project may seem like clutter, but I don't see it that way. Think of them as friends, watching your back.

Craig Newman

Re: exiting a long handler

Posted: Wed Jun 20, 2012 9:57 am
by LittleGreyMan
Hi Greg,

You could put your animation handler in a container, as an invisible field, or whatever suits you.

Then run instead something like that (pseudo-code, not tested):

Code: Select all

on animationHandler
repeat with i = 1 to the num of lines of animationCode -- the code container
get line i of animationCode
-- put exit statement here if you want to exit before the next step
do it
if cancelme = 1 then exit animationHandler -- exit after this step
end repeat
end animationHandler
It will automagically handle any number of steps, and the main handler can be modified at will.

HTH

Re: exiting a long handler

Posted: Wed Jun 20, 2012 1:54 pm
by sturgis
This method should work well enough. You'll want to have a wait with messages in your repeat loop somewhere so there is enough breathing space to set your cancel variable.

You might also study your code and see if a generic handler could be written to handle the animations. Pass the object to be animated and enough info for a function or command to determine what to do with the object. Then similar to the do method, build up a list of action lines and pass them to your function 1 by one while checking the value of your cancelling variable each iteration.
LittleGreyMan wrote:Hi Greg,

You could put your animation handler in a container, as an invisible field, or whatever suits you.

Then run instead something like that (pseudo-code, not tested):

Code: Select all

on animationHandler
repeat with i = 1 to the num of lines of animationCode -- the code container
get line i of animationCode
-- put exit statement here if you want to exit before the next step
do it
if cancelme = 1 then exit animationHandler -- exit after this step
end repeat
end animationHandler
It will automagically handle any number of steps, and the main handler can be modified at will.

HTH