Skip to content

# 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:

    gLastTime = time(),
    count = 0,
    i = 0

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!

Infinite Loop Risk

Take care when making assignments to Global and Rule-based variables in Rule Reactions when the variable is also used in trigger conditions of the same Rule. You can create an infinite loop very easily.

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