Any way to "send" exit to a handler?
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Any way to "send" exit to a handler?
Is there anything in livecode that is something between "exit" (only halts the handler it is called inside of) and "exit to top" (halts the entire callstack)?
Optimal would be some way to get the currently running handler, then tell it to stop.
I have a feeling this isn't possible, but thought I'd ask in case I've missed something.
Issue is a handler to exit out of a stack and return to a different stack. The handler closes the stack, but as soon as the exit handler is done, execution returns to the handler in a backscript that was running when the exit button was clicked and runs in the background, doing things that need to not happen. Adding "exit to top" to the exit button handler stops the execution, but takes us to the top of the stack we wanted closed, not to the other stack we'd like to return to... and since exit to top halts all execution, I can't just follow the exit to top with a go to...
So best case scenario so far is having the user click the exit button, close the stack, exit to top, stack reappears! click the exit button a second time and now it works.
Not optimal behavior.
Optimal would be some way to get the currently running handler, then tell it to stop.
I have a feeling this isn't possible, but thought I'd ask in case I've missed something.
Issue is a handler to exit out of a stack and return to a different stack. The handler closes the stack, but as soon as the exit handler is done, execution returns to the handler in a backscript that was running when the exit button was clicked and runs in the background, doing things that need to not happen. Adding "exit to top" to the exit button handler stops the execution, but takes us to the top of the stack we wanted closed, not to the other stack we'd like to return to... and since exit to top halts all execution, I can't just follow the exit to top with a go to...
So best case scenario so far is having the user click the exit button, close the stack, exit to top, stack reappears! click the exit button a second time and now it works.
Not optimal behavior.
Re: Any way to "send" exit to a handler?
Hi.
I am not understanding. This happens all the time.
If you have a hierarchy of calls, normally you would want to exit one of the two extreme ends of that hierarchy; one end is the running handler, the other end is the original calling handler. As you said...
But if you manually exit, (perhaps by having the running handler interrogate the state of the mouse or the optionKey, say?) then you can do or go anywhere you want, like send a message to any handler anywhere.
In other words, if manually,
Craig Newman
I am not understanding. This happens all the time.
If you have a hierarchy of calls, normally you would want to exit one of the two extreme ends of that hierarchy; one end is the running handler, the other end is the original calling handler. As you said...
But if you manually exit, (perhaps by having the running handler interrogate the state of the mouse or the optionKey, say?) then you can do or go anywhere you want, like send a message to any handler anywhere.
In other words, if manually,
you already have that capability. So are you asking for a way to jump over a handler or two in a long string of calls, like (pseudo, or rather fantasy):...having the user click the exit button...
Code: Select all
exit runningHandler by going back two calls
Re: Any way to "send" exit to a handler?
Separate the closing actions out into another handler in the same script, something like:
Then in the handler you want to exit:
Sending in 0 will execute the close immediately after the scripts are halted.
Code: Select all
on closeMe
close this stack
end closeMe
Code: Select all
send "closeMe" to me in 0
exit to top
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: Any way to "send" exit to a handler?
Thanks for the response.
I guess maybe the key isn't to exit the upstream handlers we're done with, but to never let their execution resume, so upon going to the target stack, instead of openCard ending and the application sitting idle until the next user input, have it start a loop that won't stop until the next mouse click.. nah, waste of resources.
Silly, I know. I did post my question in "Complete Beginners" for a reason. I was obviously barking up the wrong tree.
My guess is the best solution is to redesign some parts of the program to make sure where I want to end up is the top of a stack, then maybe, if I'm lucky, when the user clicks the exit button, I can have it close stack B, go to stack A, then exit to top and end up at the top of stack A waiting for user input. Is that a more sensible approach?
Yes, I can go wherever I want, but once I get there, and reach the end of openCard, program execution continues in the backscript that was running when the user hit the exit button, bringing us back to the stack we just closed and away from where we told it to go.dunbarx wrote:
But if you manually exit, (perhaps by having the running handler interrogate the state of the mouse or the optionKey, say?) then you can do or go anywhere you want.
I guess maybe the key isn't to exit the upstream handlers we're done with, but to never let their execution resume, so upon going to the target stack, instead of openCard ending and the application sitting idle until the next user input, have it start a loop that won't stop until the next mouse click.. nah, waste of resources.
Not looking to jump over anything, more like exit a few handlers in a row, rather than just one or all. Or, actually, exiting one handler at a time, working back up the callstack, but having that message originate outside the handler to exit, since some of the handlers are in mid-execution. Like when the exitButtons handler exits it passes exit along to the next handler, until reaching handler X.dunbarx wrote:So are you asking for a way to jump over a handler or two in a long string of calls
Silly, I know. I did post my question in "Complete Beginners" for a reason. I was obviously barking up the wrong tree.
My guess is the best solution is to redesign some parts of the program to make sure where I want to end up is the top of a stack, then maybe, if I'm lucky, when the user clicks the exit button, I can have it close stack B, go to stack A, then exit to top and end up at the top of stack A waiting for user input. Is that a more sensible approach?
Re: Any way to "send" exit to a handler?
Thanks for the helpful suggestion jacque, that solution might work too. I'll give it a try.jacque wrote:Separate the closing actions out into another handler in the same script, something like:
Then in the handler you want to exit:Code: Select all
on closeMe close this stack end closeMe
Sending in 0 will execute the close immediately after the scripts are halted.Code: Select all
send "closeMe" to me in 0 exit to top
Re: Any way to "send" exit to a handler?
Maybe make a global called "gExitNow".
Initial it as false.
In every loop in every handler add "if gExitNow then exit" and make sure there is a wait with messages clause in the loop so other event handlers get called.
Create a handler for whatever you want as an exit handler that sets gExitNow to true. For example on keydown. This could also be in an exception handler as well, or some other fatal error detector.
I'm not an expert, there may be other ways, this is what I use.
GExitNow could also be a nesting counter...
Initial it as false.
In every loop in every handler add "if gExitNow then exit" and make sure there is a wait with messages clause in the loop so other event handlers get called.
Create a handler for whatever you want as an exit handler that sets gExitNow to true. For example on keydown. This could also be in an exception handler as well, or some other fatal error detector.
I'm not an expert, there may be other ways, this is what I use.
GExitNow could also be a nesting counter...
Walt Brown
Omnis traductor traditor
Omnis traductor traditor
Re: Any way to "send" exit to a handler?
Thanks for all the tips everyone.
I tried the various suggestions, but due to the nature of the project, and the fact that the stacks I have been trying to exit out of are written by someone else and only alterable to a small extent by me, I ended up altering the program structure to some extent so that the location I am returning to multiple times is a substack rather than just a card. This allowed me to go there and then call "exit to top" and end up where I wanted to be.
Took some work to move everything around, but as with most projects, and especially this being my first real foray into LiveCode, the overall refactoring was beneficial to the whole application.
I'm still having some issues with the stacks I'm closing not actually closing, but it's pretty minor and I'm happy that the exit functionality is 90% working now.
I'll hang on to the other methods that were suggested here, as I'm sure I'll be running into situations where they will be perfect before too long.
I tried the various suggestions, but due to the nature of the project, and the fact that the stacks I have been trying to exit out of are written by someone else and only alterable to a small extent by me, I ended up altering the program structure to some extent so that the location I am returning to multiple times is a substack rather than just a card. This allowed me to go there and then call "exit to top" and end up where I wanted to be.
Took some work to move everything around, but as with most projects, and especially this being my first real foray into LiveCode, the overall refactoring was beneficial to the whole application.
I'm still having some issues with the stacks I'm closing not actually closing, but it's pretty minor and I'm happy that the exit functionality is 90% working now.
I'll hang on to the other methods that were suggested here, as I'm sure I'll be running into situations where they will be perfect before too long.
Re: Any way to "send" exit to a handler?
Hi.
I HATE trying to decipher other peoples code. I can barely decipher my own. What I mean is that if you were successful in doing that, you will have a much easier time with your own projects. Write back often with your progress and problems.
Craig
I HATE trying to decipher other peoples code. I can barely decipher my own. What I mean is that if you were successful in doing that, you will have a much easier time with your own projects. Write back often with your progress and problems.
Craig
Re: Any way to "send" exit to a handler?
I understand Craig, and trying to decipher someone's vague description of their code and what they are trying to accomplish is even more challenging!
I'm making progress now, I learned a lot getting past this roadblock and now have a better "picture" in my head of how I should be designing my projects to work well.
Thanks for your time!
John
I'm making progress now, I learned a lot getting past this roadblock and now have a better "picture" in my head of how I should be designing my projects to work well.
Thanks for your time!
John
Re: Any way to "send" exit to a handler?
Example exit with button for a movile app
on mouseUp
--codig music button app:
--put (specialFolderPath("engine") & "/soundbotones.mp3") into tPath
--play tPath
answer "¿Are you sure you want to quit?" with "NO" or "OK"
if it is "OK" then
quit this stack
close this stack
end if
end mouseUp
on mouseUp
--codig music button app:
--put (specialFolderPath("engine") & "/soundbotones.mp3") into tPath
--play tPath
answer "¿Are you sure you want to quit?" with "NO" or "OK"
if it is "OK" then
quit this stack
close this stack
end if
end mouseUp
Re: Any way to "send" exit to a handler?
??? Sure?faber3d wrote:...
quit this stack
...
Not trying to establish a new user for spamming?
I'll give you one day to explain!
