Dispatch does not switch context

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
marieinthesky
Posts: 2
Joined: Sat Oct 05, 2013 12:57 pm

Dispatch does not switch context

Post by marieinthesky » Fri Oct 18, 2013 11:09 am

Hello everybody,
I'm new to livecode and I'm trying to understand the differences between "call", "send", "dispatch" for functions and commands etc. In the livecode lesson "How to call a function or command in another object?", it is stated that:
As with "send", "dispatch" temporarily switch context when the target handler is executing.

but it doesn't seem to happen this way:
if I create a stack with 2 cards and on the first one I add a button with script:
on mouseUp
Dispatch "printmynumber" to card 2 of this stack
end mouseUp

and on the second card, I put this in the card's script:
command printmynumber
answer the id of this card
end printmynumber

So if the context is temporarily switched when executing the dispatched command, I would get the id of the second card when I click on the button on the first card,but I actually get the id of the first card. What can I do to actually get the id of the second card? (this is just an axample, actually I want to do many other things but in the context of the card where the command resides)

Thank you for your help!
Marie
P.S. the same happens if I use "send" instead of "dispatch"

marieinthesky
Posts: 2
Joined: Sat Oct 05, 2013 12:57 pm

Re: Dispatch does not switch context

Post by marieinthesky » Fri Oct 18, 2013 11:18 am

Edit:
I have found the solution: use "of me" instead of "of this card". Now I guess I have to understand the difference between "me" and "this"... so much to learn!

Post Reply