defining and using globals in an application

Nonsanity form at nonsanity.com
Thu Jul 7 12:49:58 EDT 2011


On Thu, Jul 7, 2011 at 12:11 PM, Bob Sneidar <bobs at twft.com> wrote:

> I don't think it's a bug IMHO. How can a variable in the same script have 2
> scopes? How would the app know which you were talking about when you used
> it?
>
> Bob



Ah. Variables don't a have scope, they live inside scopes.

A handler has a scope. If you "put 5 into x" in a handler, that x won't be
accessible from anywhere else. It was defined inside the scope of the
handler.

A script has a scope. If you use "local x" at the top of the script, then
all handlers in that script have access to that variable, but no other
script does. The handlers in that script are part of its scope.

The whole LiveCode environment has a scope. Any call of "global x" will add
x to the global scope. The message box lives inside that scope.

But here's the weird part that confuses many people... Even though all other
scripts can be said to be "inside the LiveCode scope" they do not have
access to the variables in that scope unless the specifically request access
to one by name with the "global" keyword. Sux to break the pattern, but
there ya go... :)

 ~ Chris Innanen
 ~ Nonsanity



More information about the use-livecode mailing list