Page 1 of 1

Target and Me

Posted: Wed Jan 22, 2014 11:26 am
by urbaud
I have a confession, I have never really understood the difference between Target and Me in LiveCode. I can imagine most of your reactions will be, “Oh My God, you gotta be kidding me, this guy should have learned this stuff in LiveCode 101”. I’m self taught in LiveCode and I have never really grasped the difference between the two. That’s why I’m asking for help from someone to direct me to a PLAIN LANGUAGE description or EXAMPLE that clearly illustrates the differences. To that someone, I thank you in advance. And, yes, I have read and re-read the dictionary and Devin Asay’s comments about them on his BYU website. Both are written in a way that hasn’t yet helped me “get it.”

Re: Target and Me

Posted: Wed Jan 22, 2014 1:13 pm
by jmburnod
Hi,

I dont use "me" but your post help me to grow up about it

Try this.
One cd with a btn.
Put this script into the cd script:

Code: Select all

on mouseup
   put "the target =" & the target & cr & "me =" & me into fld "fResult"
end mouseup
You get this result:

the target =button "Button"
me =card id 1002

Best regards


Jean-Marc

Re: Target and Me

Posted: Wed Jan 22, 2014 1:27 pm
by bn
Hi Dan,

lets make an experiment.

you make a card with some controls on it that respond to clicks. You do not want to script every control individually but you want to have one script at the card level that branches depending on which control was clicke on. Here you ask for the target.
The Target is the control that receives the mouse click and gets a mouseUp message after clicking. Since the controls do not have a script the mouseUp message go up the message path and the card is the next place where the mouseUp message passes. Here you trap the message with a
on mouseUp handler.

Me is the control/place where the currently running script is placed.

In above example where the "mouseUp" handler lives in the card script any "me" refers to the card.

see attached stack

and please don't think this is 101, I guess many from 201 would not know the difference :)


Kind regards
Bernd

Re: Target and Me

Posted: Wed Jan 22, 2014 4:27 pm
by dunbarx
What everyone said. Here is another experiment. On a new card place three fields. Name them differently. Put different text into each. Now lock all three. In each field place this script:

Code: Select all

on mouseUp
   put the short name of the target & return & me
   end mouseup
Now click on each field in turn. The target is the field name, "me" returns the field contents.

The target is probably most useful when used in Bernd's example, to oversee a large group of controls with a single handler placed at a higher level. "Me" is the contents of that control, usually a field or button, but must be accessed at the control level. That is why I responded, to show the difference from his example where me is the card.

You can put data into "me". Try it. Can you write a script that does this with those locked fields?

Craig Newman

Re: Target and Me

Posted: Wed Jan 22, 2014 4:28 pm
by FourthWorld
urbaud wrote:I have a confession, I have never really understood the difference between Target and Me in LiveCode. I can imagine most of your reactions will be, “Oh My God, you gotta be kidding me, this guy should have learned this stuff in LiveCode 101”. I’m self taught in LiveCode and I have never really grasped the difference between the two.
Don't feel bad. It was a mind-bender for me when I got started, and for many others I know.

This description helped me:

"The target" is the thing that received the message.

"Me" is the thing that contains the script being executed as a result of that message.

When you have a mouseUp handler in a button, the button is both "the target" and "me".

But if you handle mouseUp in the card script, when you click on the button, the button is "the target" and "me" is the card.

Re: Target and Me

Posted: Wed Jan 22, 2014 7:05 pm
by jacque
One caveat about "target". I see lots of people here who omit the word "the" before property names, that is, instead of using "the date" they will script only "date". This may bite you sometimes, and "target" is one of those times. LiveCode is forgiving in parsing its syntax, but if it ever starts enforcing the rules all existing scripts that omit "the" will break.

In the case of "target" your scripts will already break if you omit "the", because "the target" and "target" are two different things. This is due to compatibility with HyperCard, but it's also very useful in some situations. "The target" refers to an object, the one that received the message. "Target" (alone, without "the") refers to the text of a field.

In other words:
"put target" = "put the text of the target"

One of my pet peeves is the omission of "the", but I know some people do it to make a distinction between properties and functions. In this case, you can't.

Re: Target and Me

Posted: Fri Jan 31, 2014 3:21 am
by urbaud1
I want to thank all of you who responded to my post. Your comments and examples were very helpful to me, in fact, I think I "got it" regarding Target and Me. So, again, thanks for your help.

Dan