I read the Variable Scope FAQ, and I’m able to have handlers use and modify global variables quite nicely.
…but I’m having trouble getting handlers from another loaded script file to do the same.
Main script:
global thepath
on clicked theObject
starting()
set snippets to load script file (POSIX file (thePath & "/Contents/Resources/Scripts/snippets.scpt")
test() of snippets
end clicked
on starting()
set thePath to path of the main bundle as string
end starting
Outside script (snippets.scpt):
on test()
display dialog thePath
end test
I get an error while running my app that “The variable thePath is not defined.”.
The test() handler from snippets.scpt is not picking up the global thePath variable from the main script.
Basically, what I want to do is make dozens of “code snippets” in multiple .scpt files that I can call as if they were just copy and pasted into the main script - thus preventing clutter and allowing code reuse.
Is what I want to do completely wrong and/or impossible? Is there a little something more needed to make my global variables “globaler”?