Script Variables
Review
Script variables are areas of data that store values for how script components operate and how the script interacts with the external environment.
Variables are created when editing the script and are described in the body of the JSON structure of the script. The data area is allocated only when the script is executed.
Variables can be passed between scripts. Despite the presence of an identifier, for the convenience of editing scripts, the comparison is based on variable names.
Scope
| Scope | Description |
|---|---|
Local |
Available only to a specific script engine instance. The values are stored on its stack. |
Scenario |
Available to all instances of a specific script (by script and domain code). Stored in a shared storage on the site with a specific key (role st). |
Website domain |
Available to all scripts of the current domain executed within one site. Stored in a shared storage on the site with a specific key (role st). |
Site general |
Available to all scripts of all domains executed within one site. Stored in a shared storage on the site with a specific key (role st). |
Global domain |
Available to all scripts of the current domain, executed on any site where the domain is served. Stored in a shared storage on a site with a specific key (role st), synchronized between sites. |
Global general |
Available to all scripts of all domains, executed on any site where the domain is served. Stored in a shared storage on a site with a specific key (role st), synchronized between sites. |
If you save a value that is too large to a variable that is stored in shared storage, it is placed in the file system (category :SYNC) and the file path is automatically placed in place of the variable.
The expression functions storage_put, storage_get, storage_del allow you to create an alternative scope for stored values.
===Value types
| Value type | Description |
|---|---|
Number |
A whole number or a number with a decimal point. |
String |
String value. Stored as a structure containing a value and encoding. |
Datetime |
String value in RFC3339 format. |
Value conversion
In operations where synchronization of value types is important, values are automatically converted from one type to another.
When conversion errors occur, the behavior depends on the specific operation.
Initial values
Registered local variables are created with empty values when the script is run. They cannot be used in expressions until values are assigned.
In the Start component, it is possible to set the default mode for assigning initial values.
Initial values of local variables can also be set when running a script engine from the specific script entity settings (field opts.variables), assigned from parent processes, copied from parent scripts, etc.
Variables with a scope other than local are created only when values are directly assigned within the script.