Page 1 of 1

Passing values

Posted: Sun Apr 22, 2012 1:49 pm
by NigelS
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

Re: Passing values

Posted: Sun Apr 22, 2012 2:01 pm
by Klaus
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

Re: Passing values

Posted: Sun Apr 22, 2012 3:53 pm
by NigelS
Klaus

Cool, thanks for the reply.

Re: Passing values

Posted: Sun Apr 22, 2012 4:25 pm
by Klaus
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

Re: Passing values

Posted: Sun Apr 22, 2012 5:57 pm
by NigelS
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.