Basic question...
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Basic question...
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
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...
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~
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~
Or, if you were using this in a menu for instance,
There is a much more complete entry in the dictionary if you type "send" into the search.
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
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
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

Re: Basic question...
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.
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.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: Basic question...
Ah, I think I was mis-comprehending this part from the dictionary -

Thank you for clearing me up

Thank you for clearing me up


Re: Basic question...
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
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...
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:
Place this in the button script:
Click anywhere on the card.
You can type at will in fld 1.You can click the button.
OptionKey escapes this escapade.
Craig Newman
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
Code: Select all
on mouseUp
answer random(99)
end mouseUp
You can type at will in fld 1.You can click the button.
OptionKey escapes this escapade.
Craig Newman
Last edited by dunbarx on Wed Oct 04, 2017 3:49 pm, edited 3 times in total.
Re: Basic question...
I will try it. Thanks!
Re: Basic question...
I edited the handlers in the posting above. I think this is now a better demonstration.
Craig
Craig