Chapter 9. Script Objects
A script object
is a script within a script. In fact, a
is a script object, but it also has a special
status as the top-level script object—the script object that
contains all others.
object is defined using a block of code that starts with the keyword
script, with syntax of this sort:
scriptName-- commands within the script object end script
When typing a script definition, don’t bother to
type the full phrase
end script in the
end line. Just type
that line; the compiler will fill in the word
A script object may be defined anywhere—at top level, within a script object, or within a handler. The mere presence of a script object definition does not itself cause execution of any code within the script object. A script object’s code is run only on demand. (Later sections of this chapter, such as Section 9.2 and Section 9.3, discuss how to make such a demand.)
Like a script, a script object may contain script properties, handlers, script objects, and code. A script object is a device for organization of code and data. Related handlers, script objects, and variables can be packaged in a single self-contained script object. Also, a compiled script file can be accessed as a script object by a running script; thus a script object can function as a library of commonly needed code, or as persistent storage for variable values.
Together with variables and handlers, script objects complete a script’s “map of the world.” ...