Page 1 of 1

Referencing a text field from a different card

Posted: Tue Jun 11, 2013 3:19 am
by mgamson
Complete noob teaching myself so please bear with me if this is covered somewhere, I really have searched.

I have learned how to populate a field with "chunks" from a different text field. Unfortunately I can only do this when the text field is part of the card I am working on. I have a number of different cards I would like them all to refer back to the same text field on the original card but somehow I can't find the syntax to make this happen.

Example

on mouseUp

set the itemDelimiter to ":"

get item 1 of field "linetest"

put item 1 of field "linetest" into line 1 of field "target"

end mouseUp

This works perfect as long as the field "linetest" is located within the card.
How can I make a button on a different card refer back to "linetest" on the original card?


Thanks in advance for any help you can give.

Re: Referencing a text field from a different card

Posted: Tue Jun 11, 2013 6:01 am
by Simon
Hi mgamson,
Welcome to the forum! :)

You should lookup "name" in the dictionary
Try: "put the long name of this cd" in the Message Box (while you have your stack open).
Every control in LC has a name or ID, if you haven't directly named your Cards then your first card will be "card id 1002" then "card id 1003"etc.. (note: I hope you saw that even the name of the stack came back from the "put" above).

Since every control has a name or id you can address them directly:
"put field 1 of this cd into field 1 of cd id 1003"
Nice huh? :)
"set the label of button "myButton" of cd id 1003 to "LC is Fun!""

If I haven't been clear just write back.

Simon

Re: Referencing a text field from a different card

Posted: Tue Jun 11, 2013 7:14 am
by mgamson
WOW! brilliant!

Thank you so much. I knew I was missing something obvious. Incidentally after your suggestion, I realized the id number is displayed at the top of each property inspector window.

Thanks again for the quick response

MG

Re: Referencing a text field from a different card

Posted: Tue Jun 11, 2013 12:36 pm
by Klaus
HI MG,

I would highly recommend to give all your objects, cards and stacks meaningfull (= easy to remember!) names
so you do not need to use the IDs ;-)

And remember that you can address EVERYTHING with the correct "descriptoir", like:
...
put the text of fld "data entry" of cd "data entry card" of stack "data entry" into tVariable
...
Or even access objects from a substack in a stack that is not open:
...
put the text of fld "data entry" of cd "data entry card" of stack "data entry" of stack "path/to/stack/on_disk.livecode"into tVariable
...


Best

Klaus

Re: Referencing a text field from a different card

Posted: Tue Jun 11, 2013 9:14 pm
by mgamson
Thanks for the tip Klaus.

I actually had given the object a unique identifier called "linetest" but I could not figure out the syntax to call it up from a different card and it would not call up directly by that name. The IDnumber solved the problem but I could see how this could get confusing to keep track of without descriptive names.

Re: Referencing a text field from a different card

Posted: Wed Jun 12, 2013 5:01 am
by Simon
Hi MG,
My quick guess at the trouble is that you have to put the name in quotes, unlike ID.

put field 1 of this cd into field "linetest" of cd id 1003

Like the button example above.

Simon

EDIT:
A bit more:
put field "inputLine" of this cd into field "linetest" of cd "theOtherCard"
even more:
put field "inputLine" of cd "inputText" of stack "My First Stack" into field "linetest" of cd "theOtherCard" of stack "mySubStack"

Re: Referencing a text field from a different card

Posted: Thu Oct 20, 2022 11:10 am
by CAsba
SOLVED !
Just found I'd written 'in card "xxx"', should have been 'OF card "xxx"'
Duh !

Re: Referencing a text field from a different card

Posted: Thu Oct 20, 2022 11:15 am
by richmond62
If you keep an open mind learning LiveCode can be
a really exciting adventure.

Re: Referencing a text field from a different card

Posted: Thu Oct 20, 2022 11:16 am
by Klaus
No need to revive an almost 10 year old thread for this info... 8)

Re: Referencing a text field from a different card

Posted: Thu Oct 20, 2022 12:06 pm
by richmond62
Some people take more than 10 years to find any fun at all. :wink: