Language Guide
CHAPTER 8
Handlers
264 Scope of Script Variables and Properties
The scope of a variable declaration using the Set command within a handler is
limited to that handler:
script Henry
set theCount to 10
on increment()
set theCount to 5
end increment
return theCount
end script
tell Henry to increment() --result: 5
run Henry --result: 10
The scope of the first declaration of the first theCount variable, at the top level
of the script object Henry, is limited to the Run handler for the script object.
The scope of the second theCount declaration, within the on increment
handler, is limited to that handler. AppleScript keeps track of each variable
independently.
The scope of a local variable declaration in a handler is limited to that handler,
even if the same identifier has been declared as a property at a higher level in
the script:
property theCount : 10
on increment()
local theCount
set theCount to 5
end increment
increment() --result: 5
theCount --result: 10