I have a handler that calls a series of button scripts. I want to wait after each "send mouseUp" until the script in that button has completed before calling the next button script.
-- a handler in my card script
on myHandler
send mouseUp to cd button Num1
wait until (??) -- what do I put here
send mouseUp to cd button Num2
wait until (??) -- what do I put here
etc
end myHandler
++++++++++++++++++++++
handler on cd button Num1
on mouseUp
doSomething1 -- a call to another handler
doSomething2 -- a call to another handler
etc.
pass (??) -- is this correct
end mouseUp
Thanks for any help here. Probably a very simple solution but it evades me.
Daniel
How to wait for completion of a script
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Re: How to wait for completion of a script
Hi Daniel,
hello and welcome to the forum!
Well, this depends on what dosomething1 etc. really does!
Can't you just put everything into your myHandler?
However ususally it should work, since the dictionary (hint, hint) about "send" tells me:
...
Important: Specifying a time can affect the order in which statements are executed. If you don't specify a time, the message is sent immediately, and any handler it triggers is completed before the rest of the current handler is executed.
...
Well meant advice:
Always put quotes around strings, object names and the message to send and since LC <> HC, no need to name your controls with CD:
Best
Klaus
hello and welcome to the forum!
Well, this depends on what dosomething1 etc. really does!
Can't you just put everything into your myHandler?
Code: Select all
on myHandler
## send "mouseUp" to cd button Num1
## wait until (??) -- what do I put here
doSomething1
doSomething2
## send mouseUp to cd button Num2
##wait until (??) -- what do I put here
doSomething3
doSomething4
## etc
end myHandler
...
Important: Specifying a time can affect the order in which statements are executed. If you don't specify a time, the message is sent immediately, and any handler it triggers is completed before the rest of the current handler is executed.
...
Well meant advice:
Always put quotes around strings, object names and the message to send and since LC <> HC, no need to name your controls with CD:
Code: Select all
...
## send mouseup to cd btn Num1
send "mouseup" to btn "Num1"
...
Klaus
Re: How to wait for completion of a script
Klaus has it right, when you start a script from another object, function, handler, whatever, Lc runs that script, then comes back to where you requested it, it isn't doing things simultaneously (multi-threaded).
You can see this in action yourself in the debugger, set a break point at the beginning of your handler, then step through as the code executes. You'll see it go from the handler to the button, back to the handler, then to the next and so on and so forth, no waiting required.
You can see this in action yourself in the debugger, set a break point at the beginning of your handler, then step through as the code executes. You'll see it go from the handler to the button, back to the handler, then to the next and so on and so forth, no waiting required.
-
- VIP Livecode Opensource Backer
- Posts: 9580
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: How to wait for completion of a script
All good stuff.
I just want also to suggest that you consider the advantages of having all your functionality in a single handler if possible.
The times where individual handlers might best be placed in buttons is when the user is expected to click on those buttons. That might be the case with you. But the fact that you invoke them from another source makes me want to at least expose you to another way.
It is far easier to maintain a single script. You can use the "target" to run whatever particular functionality you require. Say you had three buttons, "B1". "B2" and "B3". Perhaps in a card script:
Click on any button, and its code portion will fire. This is all just so you see the possibilities.
Craig Newman
I just want also to suggest that you consider the advantages of having all your functionality in a single handler if possible.
The times where individual handlers might best be placed in buttons is when the user is expected to click on those buttons. That might be the case with you. But the fact that you invoke them from another source makes me want to at least expose you to another way.
It is far easier to maintain a single script. You can use the "target" to run whatever particular functionality you require. Say you had three buttons, "B1". "B2" and "B3". Perhaps in a card script:
Code: Select all
on mouseup
switch the short name of the target
case "b1"
doB1Stuff
break
case "b2"
doB2Stuff
break
case "b3"
doB3Stuff
break
end switch
end mouseup
Craig Newman