use-revolution Digest, Vol 11, Issue 42

Matt Denton matt.denton at limelight.com.au
Mon Aug 9 20:05:40 EDT 2004


Hi Jacqueline (and Richard earlier!),

Yes thanks kindly for the tip, yes I do know the difference, I remember 
crossing this bridge years ago in HyperLand.

My point was centred around duplication.  In my scripts, I regularly 
use the target as a reference to the original object.  The stack or 
group script might set a custom prop of an object, for example.  I've 
always understood 'the target' to be an absolute reference to the 
object.  It usually is.

For example, I want to remember or reference the object to say set a 
custom prop, I need an assured reference back to the object if it is 
handled down the object hierarchy.

Subtle differences:

	set the cSomeMagicValue of the target to "It works!"

... works, even if the object has been duplicated.  However:

on closeField
	put the value of the target into gKeepForLater
end closeField

... doesn't, when there are two objects with the same name, the 2nd 
object puts the value of the first object into the global.   
Interestingly, the above doesn't work even if it is in the object's 
script.  Of course 'me' always works, as does 'the name of me' or 'the 
id of me'.

Perhaps that's why 'target' was invented.

I guess prefacing with 'value of' causes Rev to convert 'the target' to 
a text name value, then get the value of that object by name, which is 
incorrect if the object has a buddy with a duplicate name.  I'll just 
stick to 'target' and the ID of the target from here on in, value of... 
doesn't seem to be reliable!  (Of course no duplicates is the best 
remedy...).

Thanks kindly to both of you!

M@
Matt

on Mon, 09 Aug 2004 17:05:49 -0500 J. Landman Gay" 
<jacque at hyperactivesw.com> wrot:

On 10/08/2004, at 8:29 AM, use-revolution-request at lists.runrev.com 
wrote:

>
>> Confusingly, just 'target' (no 'the') returns the value correctly; 
>> 'the
>> value of the target' doesn't when there is a duplicate name.
>
> One thing to note is that "target" and "the target" are two different
> things. This is a HyperCard construct and has been in xtalk languages
> since 1987, so changing it would probably break a lot of stacks.
> However, it can be confusing.
>
> "The target" is a function that identifies the object that originated
> the message. "Target" refers to the text in the object (usually a 
> field.)
>
> Create a stack with a field, and put this into the card script:
>
>   on keydown
>    put the target && target
>    pass keydown
>   end keydown
>
> The above needs refining for actual use, but should give you an idea of
> how it all works.

>> Hey ho.
>>
>> Just found a small discrepancy: the 'me' function will always return 
>> the correct object, however 'the target' will only return the name of 
>> the object.  This becomes an issue if you, like me, sometimes 
>> duplicate an object and forget to give it a unique name.  Create a 
>> button, put this script in it:
>> 	
>> on closeField
>>   put the value of me
>> end closeField
>>
>> Now duplicate (or option-drag) a copy.  Change text in the field, 
>> notice the correct values are reported back to the msg window. Now 
>> change BOTH scripts to:
>>
>> on closeField
>>   put the value of the target
>> end closeField
>>
>> ... this reports incorrectly, only reporting 1 field (the first found 
>> with the name 'Field 1').  I kinda remember in my dim past that 
>> HyperCard would always return the target value correctly, even with 
>> object name duplication?
>>
>> Confusingly, just 'target' (no 'the') returns the value correctly; 
>> 'the value of the target' doesn't when there is a duplicate name.  
>> Small, simple, but had me stumped for a bit.  As you might expect, 
>> 'put the value of (long ID of the target)' works.  Of course avoiding 
>> duplication is good practice; not trusting 'the target' is safest if 
>> you can't guarantee unique field/group/button etc names.
>>
>> I'd like to see 'the target' use the long ID for object referencing, 
>> but use the name of the target (as it does now) when used for 
>> display.  Is that possible?  Anyone agree?
>>
>> Bye
>>
>> M@
>> Matt



More information about the use-livecode mailing list