Using dispatch command to another card gives error

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

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9802
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Using dispatch command to another card gives error

Post by FourthWorld » Tue May 04, 2021 3:49 pm

cpuandnet wrote:
Tue May 04, 2021 3:39 pm
Maybe LC is getting confused between the button named "RED" with the color "Red". Have you tried naming the button something else?
It's quoted, so it's treated at as string and not a keyword.

When in doubt just be more specific with the object reference; include the card where not including it doesn't work.

I wonder if the Dictionary entry for send or dispatch has anything to say about context...
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7215
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Using dispatch command to another card gives error

Post by jacque » Tue May 04, 2021 5:15 pm

The "send" command uses the context of the target but only for scripts. "Call" uses the context of the script that makes the call. But neither of these include controls, only the message paths.

To refer to a control on a different card an explicit reference is required. If there is no explicit reference then LC assumes the current card and if the control isn't there it throws an error.

A control ID is unique and could be used, but that makes identification much harder when reading the script and isn't recommended unless you have a photographic memory.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9580
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Using dispatch command to another card gives error

Post by dunbarx » Tue May 04, 2021 5:35 pm

The issue derived from the fact the the OP sent the message to a handler on the target card, explicitly naming that card, and thought that would "bring" that card into play. It does not.

But this is in the dictionary discussion of the "call" command (my notations):
This (that is, "call") differs from the "send" command which temporarily changes the context so that object references are evaluated in the context of the object containing the target handler.
The target handler in this discussion was in the card script of the target card. I read the above as that it implies that the target card would have "become" the current card. That is, "context" as mentioned above means the card containing the target handler, which means the target card should be the current card.

In other words, as Sparkout mentioned earlier, "send" should have worked. I would assume that the change in "currency" lasts only as long as the target handler runs. But in any case, it is not so. Am I misreading the entry?

Craig

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7215
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Using dispatch command to another card gives error

Post by jacque » Tue May 04, 2021 7:27 pm

dunbarx wrote:
Tue May 04, 2021 5:35 pm
The issue derived from the fact the the OP sent the message to a handler on the target card, explicitly naming that card, and thought that would "bring" that card into play. It does not.

But this is in the dictionary discussion of the "call" command (my notations):
This (that is, "call") differs from the "send" command which temporarily changes the context so that object references are evaluated in the context of the object containing the target handler.
The target handler in this discussion was in the card script of the target card. I read the above as that it implies that the target card would have "become" the current card. That is, "context" as mentioned above means the card containing the target handler, which means the target card should be the current card.

In other words, as Sparkout mentioned earlier, "send" should have worked. I would assume that the change in "currency" lasts only as long as the target handler runs. But in any case, it is not so. Am I misreading the entry?

Craig
I may not understand what you're saying exactly, but "send" shifts the message path to the target object, whereas "call" keeps the message path at the script that made the call. The current card doesn't change, only the message path, which is temporary as you say. That said, I get an error if I don't specify a complete object reference when I use either "call" or "send" to a handler that references a control on a different card. That may be an error in the engine or in the dictionary, but I don't remember the behavior being otherwise. Bogs says it works on his older versions so maybe it changed after that.

I just checked "dispatch" and it's the same; it requires a complete object reference when sent from a different card. Using an ID does work. That is, "fld 1" fails if it isn't on the current card but "fld id 1004" does work.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

raugert
Posts: 112
Joined: Thu May 26, 2016 9:30 pm
Location: Winnipeg, Canada

Re: Using dispatch command to another card gives error

Post by raugert » Tue May 04, 2021 7:37 pm

Thank-you to all for the replies and suggestions. It's much appreciated. I tried pretty well all of the suggestions but to no avail.

Just to clarify, Craig is correct, in that I send the message to a "handler" on the target card which makes reference to objects within its card. Craig explained it much better than me :) . I also tried the "call" command but it gives the same "no such object" error.

Axwald's suggestion of using "of card" or "of me" when referring to objects, is probably a good idea. It should't be necessary, but it's seem like the only way to guarantee the objects path. I have had instances where some objects with the same card are found and others are not. As shown in image 1, all the objects are found except the widget "Test". This is even more puzzling ?

If I add "of me" to widget "Test", I get no error.. (see image 2)

Screen Shot 2021-05-04 at 1.24.20 PM.png
Screen Shot 2021-05-04 at 1.32.13 PM.png
Livecode Indy 9.6.11 (Stable)
MacOS Sonoma 14.2
Xcode 15.0.1 SDK 17.0

raugert
Posts: 112
Joined: Thu May 26, 2016 9:30 pm
Location: Winnipeg, Canada

Re: Using dispatch command to another card gives error

Post by raugert » Tue May 04, 2021 7:45 pm

Thanks Jacque for the update on using dispatch command. I will make a complete object reference in the handler.

I have another project that uses multiple substacks and uses dispatch commands to other stacks. I don't recall having the same issue, but now I better check. Hopefully it's not the same issue, as that project has a LOT of code.. :shock:

Richard
Livecode Indy 9.6.11 (Stable)
MacOS Sonoma 14.2
Xcode 15.0.1 SDK 17.0

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9580
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Using dispatch command to another card gives error

Post by dunbarx » Tue May 04, 2021 9:46 pm

Jacque;
"send" shifts the message path to the target object, whereas "call" keeps the message path at the script that made the call. The current card doesn't change, only the message path, which is temporary as you say.
Understood. The current card does not change. I guess I am reading too much into:
the "send" command which temporarily changes the context so that object references are evaluated in the context of the object containing the target handler.
In that "context of the object" is strictly message based, not environment based. The rule is navigate at all costs.

Craig

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7215
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Using dispatch command to another card gives error

Post by jacque » Tue May 04, 2021 9:51 pm

Well, not necessarily navigate, but fully reference. I think the dictionary could be clearer in its explanation.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9580
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Using dispatch command to another card gives error

Post by dunbarx » Tue May 04, 2021 10:54 pm

True.

Reference, no need to navigate. Sloppy.

Craig

raugert
Posts: 112
Joined: Thu May 26, 2016 9:30 pm
Location: Winnipeg, Canada

Re: Using dispatch command to another card gives error

Post by raugert » Wed May 05, 2021 5:31 pm

Unfortunately, it seems like the "send" command also requires the objects to be fully referenced otherwise the "no such object" error appears. This phenomenon seems to only happens between cards within the same stack. However, if I "go" to the target card first, and then issue a "send" or "dispatch" command, all is well, and no need for fully referencing objects.

If I issue the "dispatch" or "send" command from another Stack, the objects don't need to be fully referenced and no error is thrown. I would have thought, if anything, that going from stack to stack would have required some referencing.. Caveat: The target card containing the handler, must be the "active card" in its stack otherwise an error will appear.

My simplistic conclusion:
If a card is not active, the message path doesn't change to the target card when issuing a "dispatch" or "send" command, therefor full object referencing is required.

Thank-you to all for all the insights,
Richard
Livecode Indy 9.6.11 (Stable)
MacOS Sonoma 14.2
Xcode 15.0.1 SDK 17.0

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7215
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Using dispatch command to another card gives error

Post by jacque » Wed May 05, 2021 5:53 pm

I'm puzzled about the two images you posted. Before I answered I used a field on card one and a button on card two. Card 1 had a handler that referenced "fld 1" and the button on card 2 sent a message to that handler. I also tried "call" and "dispatch" and in all 3 tests I got an error.

But in your images, it worked except for the widget. So now I wonder if there really is a bug somewhere. If so, it's been around for years.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

raugert
Posts: 112
Joined: Thu May 26, 2016 9:30 pm
Location: Winnipeg, Canada

Re: Using dispatch command to another card gives error

Post by raugert » Wed May 05, 2021 6:05 pm

Hi Jacque,

I found that puzzling as well. The only thing I can think of, is that I added that widget "Test" recently. The other objects have been there for a long time. ( maybe a couple years and probably created with LC-8)
Livecode Indy 9.6.11 (Stable)
MacOS Sonoma 14.2
Xcode 15.0.1 SDK 17.0

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9580
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Using dispatch command to another card gives error

Post by dunbarx » Wed May 05, 2021 6:19 pm

Richard.
Unfortunately, it seems like the "send" command also requires the objects to be fully referenced
Yes, we earlier determined that a card reference is required for all methods. LC never changes the current card in any of them, which would be required for it to find the control of interest directly. You have to either navigate to the card, rarely desirable, or reference that card.

Craig

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7215
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Using dispatch command to another card gives error

Post by jacque » Wed May 05, 2021 6:35 pm

raugert wrote:
Wed May 05, 2021 6:05 pm
Hi Jacque,

I found that puzzling as well. The only thing I can think of, is that I added that widget "Test" recently. The other objects have been there for a long time. ( maybe a couple years and probably created with LC-8)
Are the other controls in a shared group? That might explain why they were found.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

raugert
Posts: 112
Joined: Thu May 26, 2016 9:30 pm
Location: Winnipeg, Canada

Re: Using dispatch command to another card gives error

Post by raugert » Wed May 05, 2021 6:58 pm

jacque wrote:
Wed May 05, 2021 6:35 pm
raugert wrote:
Wed May 05, 2021 6:05 pm
Hi Jacque,

I found that puzzling as well. The only thing I can think of, is that I added that widget "Test" recently. The other objects have been there for a long time. ( maybe a couple years and probably created with LC-8)
Are the other controls in a shared group? That might explain why they were found.
All the items are on the card and not grouped.

EDIT: I may have spoke too soon. I did find a group (which I thought I deleted) in the other card with the same object names. That was the cause. GOOD CALL !
Livecode Indy 9.6.11 (Stable)
MacOS Sonoma 14.2
Xcode 15.0.1 SDK 17.0

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”