• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: global variable not being recognized by script object
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: global variable not being recognized by script object
      • From: Paul Berkowitz <email@hidden>
  • Prev by Date: Re: Records
  • Next by Date: [ANN] AppleScript workshop for intermediate scripters
  • Previous by thread: Re: Handler joy (or the Joy of Reference forms)
  • Next by thread: Re: global variable not being recognized by script object
  • Index(es):
    • Date
    • Thread