Page 1 of 1
Basic question...
Posted: Sat Sep 30, 2017 10:46 pm
by Jellobus
Hello,
It may be very basic question..but I was always wondering what are differences among 3 scripts below..
1. send "customHandlerABC" to me in 0 sec
2. send "customHandlerABC" to me
3. customHandlerABC ( just add it in between scripts )
I hope anyone could explain me the differences. Thanks for your time!
Louis
Re: Basic question...
Posted: Sun Oct 01, 2017 12:21 am
by bogs
Short version-
1. you are sending a handler to <where you are putting that line> after a certain amount of time expires, in this case 0 seconds (usually not good, some delay is preferable, even if in milliseconds). For example~
Code: Select all
on timerUpdate
if tmpTime < 60 then add 1 to tmpTime
send timerUpdate to me in 1 seconds
end timerUpdate
2. Same as above, you are sending the handler to <where ever you have the line> with no delay built in.
3. you are calling the handler from an object. For example~
Code: Select all
on mouseUp
if the short name of the target is "Start Timer" then timerUpdate
end mouseUp
Or, if you were using this in a menu for instance,
Code: Select all
# This handler tells the target (me) to display the appropriate
# message in the "Message" field
on menuPick which
send "displayMessage" && which to button "Run Script"
end mouseUp
There is a much more complete entry in the dictionary if you type "send" into the search.
Re: Basic question...
Posted: Sun Oct 01, 2017 4:50 pm
by jacque
Sending a message without a time delay will pause the current handler until the sent message finishes and then continue the first handler where it left off.
Sending a message in an amount of time will cause the first handler to complete before the second one begins. LC keeps a queue of these pending messages and executes them from the earliest to the latest. It is fine to send in 0, there's always at least one idle period for the engine to do some housekeeping. In fact, sending in 0 will force the message to the top of the queue so it will be executed before any others.
Someone did some testing a long time ago and found that it is possible to even send a a message in -1 milliseconds, which would force it to the top of the queue even if there was another pending message due in 0.
Sending a message in 0 time is useful when you want to run a handler immediately after the current one ends. Sending a message to an object inside the current handler is useful when you want the command to run before the current one finishes. You don't need to use "send" if the second handler is in the message path, it is only required if the handler is in another control in general.
Re: Basic question...
Posted: Sun Oct 01, 2017 9:15 pm
by bogs
Ah, I think I was mis-comprehending this part from the dictionary -

Thank you for clearing me up

Re: Basic question...
Posted: Tue Oct 03, 2017 7:13 pm
by Jellobus
Hi bogs and jacque,
Thanks for giving me a great advice. I had hard time to figure out the differences between those scripts. It's very clear to me now. Thanks again!!
Cheers,
Louis
Re: Basic question...
Posted: Tue Oct 03, 2017 9:04 pm
by dunbarx
Just about the most important feature of sending in time is that LC is free to do anything else it might care to in the interval. The engine is released from the workings of a handler, even though that handler continues to work.
Try this. On a new card with a button and three fields, place this in the card script:
Code: Select all
on mouseUp
doStuff 100
end mouseUp
on doStuff var
if the optionKey is down then exit to top
put the mouseLoc into fld 3
add 100 to fld 2
if the mouse is down then put 0 into fld 2
send "doStuff" && var to btn 1 in 10
end doStuff
Place this in the button script:
Code: Select all
on mouseUp
answer random(99)
end mouseUp
Click anywhere on the card.
You can type at will in fld 1.You can click the button.
OptionKey escapes this escapade.
Craig Newman
Re: Basic question...
Posted: Wed Oct 04, 2017 6:04 am
by Jellobus
I will try it. Thanks!
Re: Basic question...
Posted: Wed Oct 04, 2017 3:47 pm
by dunbarx
I edited the handlers in the posting above. I think this is now a better demonstration.
Craig