Constants and Globals

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
proza
Posts: 14
Joined: Thu Jul 12, 2007 3:34 pm

Constants and Globals

Post by proza » Sat Jul 28, 2007 4:36 pm

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.

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

Post by Klaus » Sat Jul 28, 2007 5:53 pm

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

proza
Posts: 14
Joined: Thu Jul 12, 2007 3:34 pm

Post by proza » Thu Aug 02, 2007 2:33 pm

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.

Post Reply