Page 1 of 1

Global variables (yet another)

Posted: Sat Jun 14, 2014 5:17 pm
by francof
ciao to all,
a global variable to be accessible to 2 different scripts must be declared in both scripts?

thanks for your attention
franco

Re: Global variables (yet another)

Posted: Sat Jun 14, 2014 5:49 pm
by FourthWorld
With things like backscripts, libraries, and behaviors, LiveCode is very flexible, and the order of execution of scripts cannot be known by the engine in advance.

To account for this, any globals or constants used must be declared in any script that uses them.

Globals can be declared within a handler that uses them, or outside of any handlers at the top of the script so they're available to all handlers within that script.

Tip: You can also declare local variables outside of handlers, and those are available to all handlers within the script but not to any other script.

Re: Global variables (yet another)

Posted: Sun Jun 15, 2014 2:25 am
by dunbarx
What Richard said,

Note that when declaring script local variables (or globals) they must be declared above any handler within that script in order for those handlers to "see" them.

Craig Newman

Re: Global variables (yet another)

Posted: Sun Jun 15, 2014 11:55 am
by francof
ciao Richard, ciao Craig.
thank you for solving my doubt. I became crazy to understand why my global variable, declared into script A lost his string into script B. :(

franco