Page 1 of 1
Inter-Stack Messaging
Posted: Thu Apr 08, 2010 5:35 am
by WaltBrown
Hi! I have an architecture that uses multiple main stacks. They use each others data. I can send messages between them. My question is: Is their a property of a message that tells me it's sender? Or do I need to put that information in the message?
Thanks! Walt
Code: Select all
-- In stack A
send "myMessage"&myParameter to stack "Z"
-- In stack B
send "myMessage&myParameter to stack "Z"
-- In stack Z
on myMessage pParameter
-- Did this message come from stack A or B?
end myMessage
Re: Inter-Stack Messaging
Posted: Thu Apr 08, 2010 12:21 pm
by BvG
One easy way is to use "call" instead of send, and then query "the target". That works because "call" does not change the context to the receiving object, unlike "send". So your code would be this:
Code: Select all
-- In stack A
call "myMessage" && myParameter of stack "Z"
-- In stack B
call "myMessage && myParameter of stack "Z"
-- In stack Z
on myMessage pParameter
-- Did this message come from stack A or B?
if the short name of the target = "A" then
else if the short name of the target = "B" then
end if
end myMessage
Re: Inter-Stack Messaging
Posted: Thu Apr 08, 2010 1:56 pm
by FourthWorld
If you're using v3.5 or later you can also use the dispatch command. It's slightly more efficient (by about 30%, but per use that's only a fraction of a millisecond), but moreover it allows two benefits not available to send or call:
1. Params can be sent using more natural syntax, with fewer concerns about having them evaluated before they're sent
2. If the recipient doesn't handle the message you don't get an error (sometimes useful, sometimes not, but if not you can check the result to see if it contains "not handled" if you need to).
Re: Inter-Stack Messaging
Posted: Thu Apr 08, 2010 2:59 pm
by WaltBrown
Thanks! Is there any difference in the handler between Call and Dispatch in terms of the "current" card and stack?
Best, Walt