Target and Me

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
urbaud
Posts: 120
Joined: Tue Feb 24, 2009 12:10 am

Target and Me

Post by urbaud » Wed Jan 22, 2014 11:26 am

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.”
urbaud

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: Target and Me

Post by jmburnod » Wed Jan 22, 2014 1:13 pm

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
https://alternatic.ch

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4163
Joined: Sun Jan 07, 2007 9:12 pm

Re: Target and Me

Post by bn » Wed Jan 22, 2014 1:27 pm

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
Attachments
TargetAndMeDanUrbaud.livecode.zip
(1.22 KiB) Downloaded 282 times

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Target and Me

Post by dunbarx » Wed Jan 22, 2014 4:27 pm

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
Last edited by dunbarx on Wed Jan 22, 2014 4:30 pm, edited 2 times in total.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Target and Me

Post by FourthWorld » Wed Jan 22, 2014 4:28 pm

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.
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: 7389
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Target and Me

Post by jacque » Wed Jan 22, 2014 7:05 pm

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.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

urbaud1
Livecode Opensource Backer
Livecode Opensource Backer

Re: Target and Me

Post by urbaud1 » Fri Jan 31, 2014 3:21 am

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

Post Reply