What is a Script?

A script is a collection of statements that are executed in order from first to last and do not re-evaluate when variables referenced in the statement change. This is in contrast to statements in steady-state.

Scripts are created by enclosing a set of statements within a "script block" (indicated by square brackets) that in turn are preceded by an IF statement.  The IF statement and the logical expression that it evaluates, serve as the trigger for the script. When the logical condition evaluated by the IF statement becomes true, the statements with the script block will be executed once, in order as they are written.

An example of a script follows:

If test_expression;   { This line is called the action statement. }

      { The action statement triggers the script when the test    }

      { expression is true                                        }

[                 { The square bracket marks the script beginning }

  Statement 1;    { The statements with the brackets are referred }

  Statement 2;    {   to as the script statements.                }

  Statement 3;   

]                 { This bracket marks the script end.            }

 

If the test expression is still true when the last statement within the script is evaluated, and if there is no provision to transfer execution to another state, then the script will run again.  Take care to ensure that you do not create a continuously repeating loop. There are two ways to stop the script from repeating:

 

1.  Ensure that one of the statements within the script updates the conditions of the test expression so that it will become false.

2.  Provide for a state change by adding the name of another state to the action statement that triggers the script.  When the script completes, execution passes to the named state.

 

Scripts are found within states.  The following example shows a typical state structure:

Main [

  Steady state statement;           { active while Main is active }

  Another steady state statement;   { active while Main is active }

  IF  <test_expression>  State2;    { active while Main is active }

  [    { this block active only when test_expression becomes true }

     Script statement 1;  

     Script statement 1;  { last statement of the script.         }

  ]                       {  end of script section.   }

  Another steady state statement;   { also active, just like the  }

                                    { ones before the script block }

]

State2 [

  Another steady state statement;   { active while State2 is active }

  Another steady state statement;   { active while State2 is active }

]

Execution begins with state Main active.  All statements within it, including the one beginning with IF are in Steady State and therefore are active as long as Main is active.

When the test expression becomes true, the script statements run in order. Because the script's action statement ends with another state name (State2), control transfers from Main to State2 when the script finishes.

 

The statements within a script are referred to as "script statements".  This is an important distinction when referring to VTS's extensive function library.  Many functions can only be used in a script, while others can only be used in steady state. 

Note also that functions that can only be used in a script cannot be used in a tag expression.