Referencing a text field from a different card
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Referencing a text field from a different card
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.
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
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
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
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
Re: Referencing a text field from a different card
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
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
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
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
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.
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
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"
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"
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
Re: Referencing a text field from a different card
SOLVED !
Just found I'd written 'in card "xxx"', should have been 'OF card "xxx"'
Duh !
Just found I'd written 'in card "xxx"', should have been 'OF card "xxx"'
Duh !
-
- Livecode Opensource Backer
- Posts: 10095
- Joined: Fri Feb 19, 2010 10:17 am
Re: Referencing a text field from a different card
If you keep an open mind learning LiveCode can be
a really exciting adventure.
a really exciting adventure.
Re: Referencing a text field from a different card
No need to revive an almost 10 year old thread for this info... 

-
- Livecode Opensource Backer
- Posts: 10095
- Joined: Fri Feb 19, 2010 10:17 am
Re: Referencing a text field from a different card
Some people take more than 10 years to find any fun at all. 
