Re: Scope of globals, parents and children, "load script" and all that jazz
Re: Scope of globals, parents and children, "load script" and all that jazz
- Subject: Re: Scope of globals, parents and children, "load script" and all that jazz
- From: Sander Tekelenburg <email@hidden>
- Date: Sun, 20 May 2001 04:54:26 +0200
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
At 11:00 -0400 UTC, on 17/05/2001, Arthur J Knapp wrote:
>
> I'm trying to reorganize ... by separating it into a main script (parent)
>
> and ... into a separate script library (child) that is called by the main
>
> script with the "load script" command.
[...]
>
I ran some experments, (Length warning):
Took me a while, but I now understand your script :)
>
-- file "ChildScript"
[...]
>
-- file "MainScript"
[...]
>
run of LoadedChild
>
-- > { "Hello World" , 0 , "Hello World"}
>
-- byItself , asMy , asGlobal
>
(*
>
* This tells us that the loaded script was able to
>
* refer to gVariable with no problem as a normal
>
* variable within it's run handler, as well as to
>
* explicitly refer to it as a global.
>
*)
Hm... If you try to catch errors you'll notice that in this case the second
handler of the child's "on run" handler fails.
try
set asMy to my gVariable
on error
beep
say "This handler fails"
end try
[...]
>
(*
>
UseIt() of LoadedChild
>
*)
>
-- > error "The variable gVariable is not defined."
>
UseIt() of LocalChild
>
-- > "Hello World"
>
(*
>
* Within a handler, the loaded script object cannot
>
* simply refer to a global of the main script, while
>
* the local script object can.
>
*)
My point exactly ;)
[...]
>
UseGlobal() of LoadedChild
>
UseGlobal() of LocalChild
>
-- > "Hello World"
>
(*
>
* Both have no difficulties in using a global within
>
* a handler, once the variable has been explicitly
>
* declared as global.
>
*)
If I understand you correctly, you're essentially saying that the way I am
doing this is the right way. Right? (The other/better "right" way being to
not use any globals of course.)
>
[...] I wish that the whole "scope" issue of AppleScript wasn't quite so
>
complicated...
{grin}
-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <
http://www.pgp.com>
iQA/AwUBOwcx4OsywKfXgqKdEQJhwACgwtQerTqu1OnR75sjzB6y7I8LBVQAoKkv
cqvg6jEY6/CZ0qvwDGTUeNE/
=tbrG
-----END PGP SIGNATURE-----
--
Sander Tekelenburg, <
http://www.euronet.nl/~tekelenb/>
Mac user: "Macs only have 40 viruses, tops!"
PC user: "SEE! Not even the virus writers support Macs!"