Re: global variable not being recognized by script object
Re: global variable not being recognized by script object
- Subject: Re: global variable not being recognized by script object
- From: Richard 23 <email@hidden>
- Date: Wed, 28 Feb 2001 00:24:52 -0800
>
I don't know if I missed it in the 4 or 5 AppleScript books, but
>
nowhere was it explained that it is not enough to SET a variable
>
in the origin code, but you must also MARK the invokation of it
>
(by simply putting "global VariableName" on a line above it...)
>
in any external handlers/script objects (not merely reference the
>
variable by its name...
"my" also tells AppleScript to look outside of the current scope.
If a global is declared at the top level a single my reference
is sufficient (as long as the first occurence in the handler uses
my.
global foo
set foo to "bar"
TestMe()
--> "barbar"
on TestMe()
set bar to my foo
return foo & bar
end TestMe
If the global is defined anywhere other than the top-level, each
handler using a global needs to declare it global or use "my" to
reference it otherwise an undefined local is created.
R23