Scope
Scope
- Subject: Scope
- From: Paul Berkowitz <email@hidden>
- Date: Thu, 12 Dec 2002 12:56:45 -0800
I'm trying to track down an undefined variable error a user got with a
complex script of mine. It concerns a global variable which should always be
defined. (Yes, there's a good reason why I need a global variable this time:
I need to be able to refer to its value in an error trap which surrounds the
entire script.) The error message was a _system_ error message, not my own
display dialog. Ergo, the error must have been within my error handler
itself. Here's the structure: there's a main script "A" (an applet), an
assistant script "B" (compiled script) which is loaded at one point: this
global is _not_ passed to script B, and an error tracker script "C" called
from the error handler in script "A" if needed. (Because of the bug with
long scripts in AS 1.9, I need this elaborate setup.)
Script A:
global var1
try
--do stuff
set f to load script alias "path:to:script B"
tell f to set var2 to someHandler()
on error errMsg number errNum
set g to load script alias "path:to:script C"
tell g to set var3 to anotherHandler(var1)
display dialog errMsg
end try
Script C: -- no run handler, only one handler here:
on anotherHandler(var1)
--do stuff with var1
end anotherHandler
A system error (not a display dialog) appears at or near the end of the
script run:
The variable var1 is not defined.
How can it not be defined? I'm wondering if script B, which indeed does not
know about var1, is somehow imposing its scope on the error handler in
script A if another error is actually occurring during script B's run? Is
this possible? Would adding 'my' to the error handler help?
on error errMsg number errNum
set g to load script alias "path:to:script C"
tell g to set var3 to anotherHandler(my var1)
display dialog errMsg
end try
It's going to be very hard to replicate the original error since I don't
know what it is. But var1 is certainly always defined in script A and is
passed to anotherHandler(var1) in script C as a parameter, so it should be
defined there at all times - there is no other handler in script C. I can't
see anywhere that var1 is not defined, except in script B which never refers
to it. (I've checked.) And I don't have a separate local variable of the
same name anywhere in script A either.
Does anyone know what's going on?
--
Paul Berkowitz
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.