Legato
Legato

GoFiler Legato Script Reference

 

Legato v 1.4j

Application v 5.22b

  

 

Chapter ThreeData Types and Operators (continued)

3.2 Variable Scope

3.2.1 Overview

The scope of a variable refers to the context within which it was defined. On a practical level, this implies its availability to functions and operations throughout a script. Scope can be considered at two levels: global, local and object.

3.2.2 Global

Globally defined variables are available to every function and subroutine within a script. They are defined at the lowest level (outside of any particular function). They last the duration of the script’s execution, including all function calls within that script.

Globally defined variables are not available to other scripts or externally called programs.

3.2.3 Local

Locally defined variables are available to only the function in which they are defined. They last the duration of the function’s execution, including throughout the execution of functions called from within the originating function. They are not directly available to these sub functions, however, unless passed to them as a function parameter. If local handles and variables are not explicitly released, they are closed and released when the function exits. All declared variables are processed at the start of function execution, therefore, there is no economy in declaring variables inline. Inline declarations should be used for coding clarity only.

3.2.4 Object

Variables defined in an object should be considered as “belonging” to that object. They may be accessed by functions inside of the object. They may also be accessed by other functions that have access to the object according to the object’s scope. 

3.2.5 Loop

Variables defined as part of a for loop iteration statement exist only throughout the execution of the loop. These are usually counting variables. For example:

for (i = 0; i < count; i++) {

... some code ...

    }

In this case, i is initialized at the start, each pass 1 is added to i until i is equal to or larger than count.