Passing Field value from 1 card to another card

Visit here to inform or invite LiveCode users to user groups, meetings, conventions or other gatherings. Events must be related to LiveCode.

Moderators: Klaus, FourthWorld, robinmiller

Post Reply
trags3
Posts: 215
Joined: Wed Apr 09, 2014 1:58 am
Location: Las Vegas, NV

Passing Field value from 1 card to another card

Post by trags3 » Wed Apr 09, 2014 2:11 am

I have a text input field named salesprice on card 2 of the stack.
I want to display that value in a text field on the next card when I open card 3 of the stack.
I am brand new to this. I tried using the on openCard handler on card 3 but everything Ive tried produces nothing.
The on openCard handler send a message when I open any card and I get an error message on cards that don't have the salesprice field on them.

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3900
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: Passing Field value from 1 card to another card

Post by Simon » Wed Apr 09, 2014 3:14 am

Hi trags3,
Welcome to the forum! :)

There are lots of ways of doing what you'd like but I think understanding how liveCode thinks (message path) is a better starting place. Take a look at this:
http://lessons.runrev.com/s/lessons/m/4 ... ssage-path
Notice how everything is "single" that is you only see 1 card and 1 stack in the image. That is part of your answer:

Code: Select all

on openCard
put 2 into field "myField"
end openCard
Since it is "single" it can only look at itself (the card) for a field called "myField" it has no notion of other cards in the stack.
But of course liveCode has a way to deal with this.

Code: Select all

on openCard
put 2 into field "myField" of card "mySecondCard"
end openCard
Now you have told it not to look at itself but some other card.
also

Code: Select all

on openCard
put field "price" of card "myFirstCard" into field "myField" of card "mySecondCard"
end openCard
I wouldn't actually use on openCard probaly more on closeCard because you can use
put field "price" of this card into field "myField" of card "mySecondCard"

Can you figure out how to write your scripts from that?

Simon
Edit:
Another great resource
http://www.hyperactivesw.com/revscriptc ... ences.html
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

trags3
Posts: 215
Joined: Wed Apr 09, 2014 1:58 am
Location: Las Vegas, NV

Re: Passing Field value from 1 card to another card

Post by trags3 » Wed Apr 09, 2014 3:26 am

Simon, Thanks, I'll try that.

trags3
Posts: 215
Joined: Wed Apr 09, 2014 1:58 am
Location: Las Vegas, NV

Re: Passing Field value from 1 card to another card

Post by trags3 » Wed Apr 09, 2014 3:02 pm

Simon, Thanks for the help I used the "on closecard" handler and that works great!

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3900
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: Passing Field value from 1 card to another card

Post by Simon » Wed Apr 09, 2014 9:57 pm

Glad I could help :)

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

Post Reply

Return to “User Groups and Gatherings”