Script Action
The Script Action action in a Reaction will run the provided script, which is a Reactor expression.
The script has access to all defined global variables. If the Script Action is in a Rule-local Reaction (i.e. a SET or RESET Reaction in a Rule), it also has access to all of the Rule-local expressions/variables defined by the Rule. They are automatically in scope, with their configured names and last values.
The script may use global or Rule-local variables on the left side of an assignment operator; that is, scripts can set values on global or Rule-local variables. Consider the following script:
This script is a compound statement; it has three distinct statements that will be executed. Assuming gLastTime
is the name of an expression-less global variable already defined, the first statement will set the value of that global variable to the current time. Assuming count
is the name of an expression-less Rule-local variable, its value will be set to 0. Assuming i
is neither a known global or Rule-local variable, it will be defined as a temporary local variable in the script. Such temporary local variables are only available within the script at the current step of the Reaction; they will not be available anywhere else in the Reaction, including other Script Actions.
Know Your Variables!
In an assignment where the identifier on the left side of the equal sign (=
) is unknown (i.e. the target variable isn't already defined in any scope), the default behavior of the expression language is to silently create a temporary local variable. If you misspell the name of a global or Rule-local variable in an assignment, a local variable will therefore be created without warning. You may then observe that your intended global or Rule-local variable is not changing as expected. Remember: spelling and case are significant in expressions!
Naming Collisions
If you have a global variable and a Rule-local variable with the same name (i.e. a name collision between two different levels of scope), and the rule's SET or RESET Reaction contains a Script Action script that refers to that name, the expression language will see the Rule-local variable first. There is no way to "see past it" to access the global variable; you will have to change the name of one or the other. This is the reason many programmers use naming conventions like Hungarian Notation.
When a Script Action changes a global or Rule-local variable, the rules for dependent variables and triggering other events are the same as for the Set Variable action.
See also Expressions & Variables and Set Variable action.
Updated: 02-Sep-2025