Passing control away and back again

Paul Dupuis paul at researchware.com
Sun Feb 15 17:41:42 CET 2015


On 2/15/2015 10:02 AM, Graham Samuel wrote:
> But I do understand Paul's, which was very near the approach I was thinking of taking myself. I suppose I am still worried about the 'send'. Sending isn't calling, is it? I mean, in principle, a handler like "dopart2" in Paul's example will be executed, and then control will return to the script that executed the 'send', won't it? So we end up executing "end mouseUp" in the context of the button that was clicked, not the script that was running in the 'startUp' handler. Perhaps this doesn't matter, but this is the issue I'm trying to get my head around. Anyway it's a viable solution and I'm grateful.

send <message> to <object> -- is like a call. The handler waits until
message is executed before proceeding to the next statement

send <message> to <object> in <time> -- places the message in the
message queue and the handler continues. The message queue then invokes
the message in the allotted time.

So,

on mouseUp
  close this stack
  send "doPart2" to <main stack>
end mouseUp

will not do what you want as the send executes "doPart2" and the
completes the mouseUp, but

on mouseUp
  close this stack
  send "doPart2" to <main stack> in 10 milliseconds -- or some non-zero time
end mouseUp

causes doPart2 to execute in the context of the main stack AFTER the
mouseUp handler has completed.

If I recall correctly, Richard Gaskin produced an excellent short 1 or 2
page guide on message passing in LiveCode. A *must have* reference if
you're still learning all the ins and outs. It looks like he's expanded
it from the one I remember as well. See
http://www.fourthworld.com/embassy/articles/revolution_message_path.html




More information about the use-livecode mailing list