Page 1 of 1
Constants and Globals
Posted: Sat Jul 28, 2007 4:36 pm
by proza
I would like to know how to declare constants and globals so that they can be used in every single card and every single object in a stack (maybe the sub stacks as well).
Thanks!
Proza
P.S. I tried to put the declaration on the top of the stack script, but only the handlers on the stack script can see them. The handlers on the card scripts and object scripts cannot see them.
Posted: Sat Jul 28, 2007 5:53 pm
by Klaus
Hi proza,
constants are local!
So you can put them on the top of a script and use it in any handler in that script, as you already found out
Globals are erm global...
You can declare them anywhere and anytime you want and they are valid and accessible in THAT very moment.
But you have to tell the engine in every handler THAT you're gonna use it.
e.G.
Code: Select all
on preopenstack
global your_global
put "my global" into your_global
...
end preopenstack
then you can use and alter this variable in every handler in your stack like:
Some button:
Code: Select all
on mouseup
global your_global
answer "This is" && your_global &&" and not yours!"
put "your global" into your_global
answer "This is" && your_global &&" and not mine!"
...
end mouseup
Well, that's it, basically
Have a nice weekend.
Best from germany
Klaus
Posted: Thu Aug 02, 2007 2:33 pm
by proza
Thanks.
I found that the best way is to declare the contants as globals on the top of the stack script, then put values to them in the preOpenStack handler. Whenever I need the constants, I just declare them on the top of the script.