Passing control away and back again

Bob Sneidar bobsneidar at iotecdigital.com
Tue Feb 17 00:47:38 CET 2015


I forgot to mention that you can go to a stack as modal, so you can put all these setup cards in a setup stack, then go to that stack modal (once it’s debugged of course). That way script execution in the calling stack will be suspended until you close the modal stack. My Database Merger stack works that way.

Bob S


On Feb 16, 2015, at 15:45 , Bob Sneidar <bobsneidar at iotecdigital.com<mailto:bobsneidar at iotecdigital.com>> wrote:

On 2/15/2015 7:14 AM, Graham Samuel wrote:
This is probably very dumb, but I've got into a muddle thinking about " 'Go To' Considered Harmful", if anyone is old enough to remember that Dutch utterance... anyway:

In LC, really everything is dealt with in handlers which begin, execute and end and can be nested within one another. So how do you construct a control structure like the following:

1. The program starts up with a 'startup' handler (could use 'preOpenStack' but it's not so good). The script there does setting-up things, and then it notices that it needs extensive user input (for example, maybe the program isn't registered and we need some details - even maybe payment) before we can go on.

2. To get the user input, the script does a 'go to' (which is really an 'open') to a special stack for this input. Eventually, the data is input and checked, and the user clicks say an "OK" button to get back to the startup process.

3. What happens now? The script can't easily resume the original startup handler, can it? After all, the special stack which deals with user input is not a handler nested within the startup handler. The "OK" button is driven by a 'mouseUp' handler, but when that handler closes, there is no automatic way of going back to the calling handler of the whole process (the startup handler) due to the lack of nesting. What the script **can** do is to invoke a further handler in the original card where the startup is, called perhaps 'continueStartup', so that at the end of the 'mouseUp' script, we simply call this new handler.

This kind of works, but we are left with loose ends: the original 'startup' handler never reaches its termination point ('end startUp') as far as I can see, and the 'resume' script doesn't exactly terminate either, does it? If it did, we'd end up in the 'mouseUp' script in a stack (window), which is probably closed by now, having done its job. So viewed as a set of control structures, it looks a mess.

OK, there is a way of doing it, kind of, but what is the most logical way to approach this problem of non-nested control structures?






More information about the use-livecode mailing list