The send command vs the call command

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
nlexa
Posts: 26
Joined: Fri Aug 05, 2011 2:34 am

The send command vs the call command

Post by nlexa » Fri Aug 05, 2011 2:57 am

Make a new stack
Make 2 cards

On card 1 create a text field and name it "theField"
In field "theField" script write the custom command:

on thisCommand
put "Blue" into field "theField"
end thisCommand


On card 2 create a button
on mouseUp
send "thisCommand" to field "theField" of card 1
end mouseUp

Press the button on card 2 and see if it works;
You should get this error:
field "theField": execution error at line 2 (Chunk: no such object) near "theField", char 15

if however you change 'thisCommand' to say:

on thisCommand
put "Blue" into field "theField" of card 1
end thisCommand

Then it works and puts the word "Blue" into the field.
I don't understand how the command cannot find the field in the first example and causes the error.

If I were to call this command from card 1 from a similar button it would work.
Make a button on card 1 and in the script write:

on mouseUp
send "thisCommand" to field "theField"
end mouseUp

Does this mean every object I reference in a custom command that I intend to use with the 'send' command from another card need to be explicitly declared ( of card 1 ).
I assume the answer is yes.

After having just read the manual section entitled "The send Command versus the call Command" I find this behaviour peculiar and contrary to the manual.
Can someone correct me?

BarrySumpter
Posts: 1201
Joined: Sun Apr 24, 2011 2:17 am

Re: The send command vs the call command

Post by BarrySumpter » Fri Aug 05, 2011 5:41 am

yes, very interesting question and behaviours.
Thats an intricate question for your first post.
Welcome to the forums.

I'd prefer you upload a complete .livecode project to make it easier and to ensure we're testing the same project.

I thnk error is expecting field "theField" to be on card 2 and can't find it.

But I've drawn the same logical conclusion from your post without actually testing it myself.
5.8.6 The send Command versus the call Command
The call command is similar to the send command. Like the send command, the
call command sends a message to the specified object, allowing you to use handlers
that aren't in the message path.
The difference between send and call is how they handle object references in the
handler that is triggered by the sent message. If the message is sent by the send
command, object references in the handler are treated relative to the object you sent the
message to.

For example, suppose card 1 of a stack contains the following handler:

Code: Select all

on showCard
answer the number of this card
end showCard
If a handler in the script of card 3 uses the send command to send a "showCard"
message to card 1, the dialog box displays "1", the number of the card the handler is on.
However, if the same handler uses the call command instead, the dialog box displays
"3", the number of the card that used the call command. In other words, handlers that
are triggered by the send command use the context of the object the handler is in, while
handlers that are triggered by the call command use the context of the object that
triggered the handler
.
All my best,
Barry G. Sumpter

Deving on WinXP sp3-32 bit. LC 5.5 Professional Build 1477
Android/iOS/Server Add Ons. OmegaBundle 2011 value ROCKS!
2 HTC HD2 Latest DorimanX Roms
Might have to reconsider LiveCode iOS Developer Program.

nlexa
Posts: 26
Joined: Fri Aug 05, 2011 2:34 am

Re: The send command vs the call command

Post by nlexa » Mon Aug 08, 2011 12:25 am

I would love to upload the .livecode file but the file extension is not allowed. neither is .txt and I can't trick it with .jpg
The difference between send and call is how they handle object references in the
handler that is triggered by the sent message. If the message is sent by the send
command, object references in the handler are treated relative to the object you sent the
message to.
As far as I can tell, this is rubbish. This is frustrating. I'm trying to learn livecode and when I write myself an example to test, it doesn't behave anything like the manual entry.

SparkOut
Posts: 2947
Joined: Sun Sep 23, 2007 4:58 pm

Re: The send command vs the call command

Post by SparkOut » Mon Aug 08, 2011 12:27 am

Try zipping the file first, it should be accepted for upload then.

BarrySumpter
Posts: 1201
Joined: Sun Apr 24, 2011 2:17 am

Re: The send command vs the call command

Post by BarrySumpter » Mon Aug 08, 2011 1:37 am

There are some restrictions for new forum members.

Hyperlinks were allowed only after 10 posts or 7 days.
To keep spammers away.

Don't know the rules for attachments.
All my best,
Barry G. Sumpter

Deving on WinXP sp3-32 bit. LC 5.5 Professional Build 1477
Android/iOS/Server Add Ons. OmegaBundle 2011 value ROCKS!
2 HTC HD2 Latest DorimanX Roms
Might have to reconsider LiveCode iOS Developer Program.

nlexa
Posts: 26
Joined: Fri Aug 05, 2011 2:34 am

Re: The send command vs the call command

Post by nlexa » Mon Aug 08, 2011 5:22 am

Sendcommandproblem.zip
(903 Bytes) Downloaded 289 times
thanks guys. I will be interested to see what I did wrong.

Klaus
Posts: 14194
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: The send command vs the call command

Post by Klaus » Mon Aug 08, 2011 12:24 pm

Hi nlexa,

you did nothing wrong and this is correct behavior! :D

This is not easy to explain...

The "world" of LiveCode consists of the current card only, so when you "send" you handler to a button on another card,
that handler will also only "see" the current card and does not find that namely field!
But it DOES if we are (the LiveCode "world" is) on the card with the button!

So you should simply add a descriptor of that card (number or name) and everything will be fine:

Code: Select all

on thisCommand
  put "Blue" into field "theField" OF CD "name of card here"
end thisCommand
Just like you did in your "send" handler!
...
send "thisCommand" to field "theField" of card 1
...


Best

Klaus

nlexa
Posts: 26
Joined: Fri Aug 05, 2011 2:34 am

Re: The send command vs the call command

Post by nlexa » Tue Aug 09, 2011 1:35 am

Thanks Klaus! I thought that might be the case because I tried using:

on mouseUp
go to card 1
send thisCommand to field "theField" of card 1
end mouseUp

this works because it goes to the card before it sends the message to it.
In any case I had to hear it from someone else to be sure that:
The "world" of LiveCode consists of the current card only

Klaus
Posts: 14194
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: The send command vs the call command

Post by Klaus » Tue Aug 09, 2011 1:27 pm

Yep, it's a small world, but the best (and only) we have 8)

Post Reply