Previous Page
Next Page

8.1. Script Object Definition

A script object is defined using a block with the keyword script:

script scriptName
    -- commands within the script object
end script

A script object definition may appear anywhere. If defined at the top level of a script object (or script), it is a top-level entity ("Top-Level Entities," later in this chapter). It functions as a scope block . (The rules of scope appear in Chapter 10.) Read Chapter 6 for an overview of how script object definitions fit into a script's overall structure.

A script object definition is just thata definition. Merely encountering a script object definition in the course of execution does not cause of any of its commands to be executed. Rather, a script object definition is a form of variable initialization. So, for example:

script s
    display dialog "howdy"
end script

That code does not cause a dialog to display. It defines a script object with an implicit run handler; that run handler contains code that puts up a dialog, but the mere definition does not cause the run handler to run. The script object itself is the value of a variable. Here, that variable is s; when this code is encountered, the variable s is defined and initialized, and its initial value is the script object described by this block of code.


Previous Page
Next Page