Page 1 of 1
Send in the dictionary
Posted: Fri Dec 06, 2013 10:46 am
by chris25
This comment in the dictionary has me considering the following: When a send command is sent and completed in some action, it is done. I presume by the need to cancel that what is happening is that it is done, but still in the loop taking up valuable processor time, and therefore needs to be actually physically removed/cancelled so that it does not show up as a pending message. Am I understanding this correctly? Is this why it needs to be cancelled sometimes, under what circumstances then would it need to be cancelled? (although in all scripts where I have seen this command being used I have never once seen it cancelled), hence the need to ask.
chris
About "result".
Though explained in the Comments, the use of "result" after "send" is easy to overlook, so am adding an example for future reference.
Example:
send SomeMessage to me in 50 miliseconds
put the result into SomeMessageID
..
cancel SomeMessageID
Re: Send in the dictionary
Posted: Fri Dec 06, 2013 12:04 pm
by Mark
Hi Chris,
Suppose you want to show a blinking indicator while executing a repeat loop:
Code: Select all
on somethingComplicated
send "foo" to me in 0 millisecs // start blinking now
put the result into lFooMessageID
repeat with x = 1 to 10000 with messages
// do complicated things with buttons and fields here
// taking quite some time
wait 0 millisecs with messages
end repeat
cancel lFooMessageID
end somethingComplicated
on foo
set the hilite of btn "Blink" to not the hilite of btn "Blink"
send "foo" to me in 500 millisecs
put the result into lFooMessageID
end foo
However, if foo is called by multiple handlers, this might not work very well. Most of the time, I use a different way to cancel a pending message:
Code: Select all
put the pendingMessages into myMessages
filter myMessages with "*,foo,*"
repeat for each line myMsg in myMessages
cancel item 1 of myMsg
end repeat
Kind regards,
Mark
Re: Send in the dictionary
Posted: Fri Dec 06, 2013 1:04 pm
by chris25
Hallo Mark, just to make sure I understand this, Oh that second script - thankyou, brilliant. The first script.
My comments after ====
on somethingComplicated
send "foo" to me in 0 millisecs // start blinking now ==== to 'me' in this case as long as the indicator's script is on the same stack as this script?
put the result into lFooMessageID ==== otherwise without this ID then it can not be cancelled?
repeat with x = 1 to 10000 with messages ==== 10000 being the max number of times it can blink? And with messages in order to allow for other handlers to execute otherwise this blinking would block all messages that must travel beyond this level in the hierarchy?
// do complicated things with buttons and fields here
// taking quite some time
wait 0 millisecs with messages ===Mmm, never understood this wait 0 milliseconds, why not leave it out, is that not the same as don't wait carry on sending messages?
end repeat
cancel lFooMessageID === just to be absolutely clear, if I were to put multiple message ID's into a variable I would have to insert the physical numbers of each Message ID? This ID would come by inserting "foo" into the message box with a send messageID of "foo" ? yep, think I am a bit wobbly here.
end somethingComplicated
on foo
set the hilite of btn "Blink" to not the hilite of btn "Blink" ==== another thing that has bewildered me is the often seen use of this syntax, in other words cancel the hilite of "blink" right?
send "foo" to me in 500 millisecs
put the result into lFooMessageID
end foo
regards
chris
Re: Send in the dictionary
Posted: Fri Dec 06, 2013 2:40 pm
by Klaus
Hi Chris,
chris25 wrote:
...
set the hilite of btn "Blink" to not the hilite of btn "Blink"
###another thing that has bewildered me is the often seen use of this syntax, in other words cancel the hilite of "blink" right?
...
not really
This will set a BOOLEan value (which can be TRUE or FALSE = just like the hilite of a checkbox or radio button) to the OPPOSITE of its value!
Maybe some parens will make it clearer:
...
set (the hilite of btn "Blink") to NOT (the hilite of btn "Blink")
...
Now replace the values in parens and see if you can guess the result of that line with the different values.
Actually this is some kind of cool "ON/OFF" switch, which always works without looking
...
## Not hilited yet, so turn it on:
set (FALSE) to NOT (FALSE)
...
## Hilited, so switch it OFF
set (TRUE) to NOT (TRUE)
...
You know what:
NOT (FALSE)
and
NOT (TRUE)
will mean, right?
Best
Klaus
Edit:
Find more "Fun with Boole" in my last posting here:
http://forums.runrev.com/phpBB2/viewtop ... 69&t=17552
Re: Send in the dictionary
Posted: Fri Dec 06, 2013 3:01 pm
by chris25
Yes it seems a little clearer now, actually when you said it was a kind of cool on off switch actually clinched it, just having to adjust my logic here a bit. thanks Klaus, it makes sense now. By the way, I thought people might be interested in this:
http://en.wikipedia.org/wiki/George_Boole
I walked past this house often it is right next to the city centre, there is a plaque here about good old George, but as with everything here it is overgrown with weeds and dereliction. The photo second down is actually a little bit of how his house still looks - the top room is where he did all his mathematics.
regards chris
Sorry, missed that link to your last post, thankyou for that reminder, getting right on it.