Passing values

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
NigelS
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 83
Joined: Sat Oct 22, 2011 2:37 pm

Passing values

Post by NigelS » Sun Apr 22, 2012 1:49 pm

I'm not sure if this has not been asked already, if it has, please excuse me.

How does one pass a value from one card to another?

Thx

Klaus
Posts: 14194
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Passing values

Post by Klaus » Sun Apr 22, 2012 2:01 pm

Hi Nigel,

well, it depends :D
You could use GLOBAL variables or store values into a custom property of your stack or card or whatever.
...
## Store the content of the Vatiable tValue in a custom property of the current stack
## you can name the custom properties as you like, as long as they are not a "reserved word" in LiveCode
## I alway add a c at the beginning of the name:
set the cValueStorage of this stack to tValue
...
From now on you can access and modify that cp from everywhere in your stack(s):
...
put the cValueStorage of this stack into fld "value display"
put the cValueStorage of stack "other stack" into tValuet2
## etc...
...
Unlike variables (local or global) custom properties will get saved with the stack (in the IDE)!


Best

Klaus

NigelS
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 83
Joined: Sat Oct 22, 2011 2:37 pm

Re: Passing values

Post by NigelS » Sun Apr 22, 2012 3:53 pm

Klaus

Cool, thanks for the reply.

Klaus
Posts: 14194
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Passing values

Post by Klaus » Sun Apr 22, 2012 4:25 pm

Hi Nigel,

my pleasure!

Hint: Modifying CPs is a bit different since they cannot be edited directly!

You CANNOT:
...
delete line -1 of the cValueStorage of this stack
...


You need to do something like this:
...
## store in variable
put the cValueStorage of this stack into tTemp

## modify content of variable
delete line -1 of tTemp
## more stuff here...

## (over) write variable back to CP
set the cValueStorage of this stack to tTemp
...


Best

Klaus

NigelS
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 83
Joined: Sat Oct 22, 2011 2:37 pm

Re: Passing values

Post by NigelS » Sun Apr 22, 2012 5:57 pm

Klaus

Been reading up on Custom Properties and by using GetProp and SetProp, it fits my requirements perfectly for what I want to do. These two also remind me if the Set/Get properties of C# and seem to have the same functionality.

Once again thanks for your input.

Post Reply