Page 1 of 1

Passing Field value from 1 card to another card

Posted: Wed Apr 09, 2014 2:11 am
by trags3
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.

Re: Passing Field value from 1 card to another card

Posted: Wed Apr 09, 2014 3:14 am
by Simon
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

Re: Passing Field value from 1 card to another card

Posted: Wed Apr 09, 2014 3:26 am
by trags3
Simon, Thanks, I'll try that.

Re: Passing Field value from 1 card to another card

Posted: Wed Apr 09, 2014 3:02 pm
by trags3
Simon, Thanks for the help I used the "on closecard" handler and that works great!

Re: Passing Field value from 1 card to another card

Posted: Wed Apr 09, 2014 9:57 pm
by Simon
Glad I could help :)

Simon