How do u use a field from one card in code on the next card?

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
mikemc
Posts: 60
Joined: Sun May 10, 2015 5:42 pm

How do u use a field from one card in code on the next card?

Post by mikemc » Thu May 14, 2015 3:23 am

I have a stack with five cards. I want to use fields from the first card in a calculation on the second card but
for some reason it does not recognize the field name in my code on the second card.

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: How do u use a field from one card in code on the next c

Post by Simon » Thu May 14, 2015 4:24 am

Code: Select all

put fld "myCard1" into fld "myCard2" of cd 2
You'll have to get the names right.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

SparkOut
Posts: 2961
Joined: Sun Sep 23, 2007 4:58 pm

Re: How do u use a field from one card in code on the next c

Post by SparkOut » Thu May 14, 2015 6:41 am

Simon's code will work from card one to "pre-fill" a field on card two.

If you want to refer to a field on another card you can easily do it by adding it's parentage in the hierarchy. As Simon does by saying he wants the data from the first field to go into a field on card 2.
So while in the script on card 2 you can pull the data from another card

Code: Select all

put field "fieldOne" of card "cardOne" into field "fieldTwo"
You can even get it from another stack, if you wish

Code: Select all

put field "fieldOne" of card "cardOne" of stack "theOtherStack" into field "fieldTwo"

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

Re: How do u use a field from one card in code on the next c

Post by dunbarx » Thu May 14, 2015 7:25 pm

What everyone said.

When you: put foo into fld 2, you are really taking a shortcut. It should be: put foo into fld 2 of cd "cardDescriptor" of stack "stackDescriptor". When the card is the current card and the stack is the current stack, you can omit the full referencing of these objects.

Any card on any open stack, and all its resident objects, are accessible at any time. You can move data (or objects) from where you are to anywhere else, and vice-versa. You just have to specify the path. The "shortcuts" I mentioned are often taken for granted, and lead to a false sense of insecurity, hiding the flexibility that LC offers in this sort of transaction. This often trips new users.

Craig Newman

mikemc
Posts: 60
Joined: Sun May 10, 2015 5:42 pm

Re: How do u use a field from one card in code on the next c

Post by mikemc » Fri May 15, 2015 12:37 am

That was all very helpful thankyou

Post Reply