How does a command find out who called it?
Richard Gaskin
ambassador at fourthworld.com
Wed Feb 1 20:02:19 EST 2012
Bob Sneidar wrote:
> Dispatch does not have an "in time" argument. Only send does.
> The other difference is that send temporarily changes the
> defaultStack to the one containing the called handler. Any
> references to "this card" or "this stack" will reference the
> target stack, not the stack the handler was called from.
> Dispatch does not do this. It can be a gotcha if you are not
> aware of it.
Are you thinking of "call"?
I just ran this test:
1. Make a new stack "aaa", and name the card "aaaaaaaaa"
2. Make a new stack "bbb", and name the card "bbbbbbbbb"
3. Add a button to "bbb" with this script:
on foo
put the name of this cd
end foo
4. Click stack "aaa" to bring it to the front
5. Run these in the Message Box
send "foo" to btn 1 of stack "bbb"
RESULT: card "bbbbbbbbb"
dispatch "foo" to btn 1 of stack "bbb"
RESULT: card "bbbbbbbbb"
call "foo" of btn 1 of stack "bbb"
RESULT: card "aaaaaaaaa"
Interestingly, a similar test using different cards in the same stack
yields a different result:
1. Make a stack with two cards, one named "aaa" and the other "bbb"
2. On card "bbb" add a button with the "foo" handler above
3. Go to card 1 ("aaa") and run these in the Message Box:
send "foo" to btn 1 of cd "bbb"
RESULT: card "aaa"
dispatch "foo" to btn 1 of cd "bbb"
RESULT: card "aaa"
call "foo" of btn 1 of cd "bbb"
RESULT: card "aaa"
Should we expect "send" and "dispatch" to switch context with the card
reference?
--
Richard Gaskin
Fourth World
LiveCode training and consulting: http://www.fourthworld.com
Webzine for LiveCode developers: http://www.LiveCodeJournal.com
LiveCode Journal blog: http://LiveCodejournal.com/blog.irv
More information about the use-livecode
mailing list