Global variables (yet another)

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
francof
Posts: 237
Joined: Fri Apr 11, 2014 10:51 am

Global variables (yet another)

Post by francof » Sat Jun 14, 2014 5:17 pm

ciao to all,
a global variable to be accessible to 2 different scripts must be declared in both scripts?

thanks for your attention
franco

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10053
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Global variables (yet another)

Post by FourthWorld » Sat Jun 14, 2014 5:49 pm

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.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10335
Joined: Wed May 06, 2009 2:28 pm

Re: Global variables (yet another)

Post by dunbarx » Sun Jun 15, 2014 2:25 am

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

francof
Posts: 237
Joined: Fri Apr 11, 2014 10:51 am

Re: Global variables (yet another)

Post by francof » Sun Jun 15, 2014 11:55 am

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

Post Reply