LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
WaltBrown
- Posts: 466
- Joined: Mon May 11, 2009 9:12 pm
Post
by WaltBrown » Thu Apr 08, 2010 5:35 am
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
Walt Brown
Omnis traductor traditor
-
BvG
- VIP Livecode Opensource Backer

- Posts: 1239
- Joined: Sat Apr 08, 2006 1:10 pm
-
Contact:
Post
by BvG » Thu Apr 08, 2010 12:21 pm
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
Various teststacks and stuff:
http://bjoernke.com
Chat with other RunRev developers:
chat.freenode.net:6666 #livecode
-
FourthWorld
- VIP Livecode Opensource Backer

- Posts: 10052
- Joined: Sat Apr 08, 2006 7:05 am
-
Contact:
Post
by FourthWorld » Thu Apr 08, 2010 1:56 pm
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).
-
WaltBrown
- Posts: 466
- Joined: Mon May 11, 2009 9:12 pm
Post
by WaltBrown » Thu Apr 08, 2010 2:59 pm
Thanks! Is there any difference in the handler between Call and Dispatch in terms of the "current" card and stack?
Best, Walt
Walt Brown
Omnis traductor traditor