Variables are a convenient way to store and use data in bot scripts. They work like named "containers" that the bot creates automatically when it encounters them for the first time. Initially, a variable is always empty and has the value nil.
All variables fall into three types based on their scope:
Flow variables (local variables). These variables work only within the current flow — a sequence of actions executed by the bot. They are great for temporary data storage, such as intermediate calculations. Their names start with the $ symbol.
Example:
$p = 2 * 3.14 * $radius // The variable $radius is only available in the current flow
Module variables. Available in all flows within the same module. Useful when you need to share data across flows of a single script. Their names start with the # symbol.
Example:
#count = queue.size() // The variable #count is available in all flows of the current module
Global variables (environment variables). Global variables are visible everywhere: in all modules and flows. They contain information about the bot’s current state and execution context. Their names start with the @ symbol. These variables are read-only.
Example:
$isChat = @communicationType == "TEXT" // The global variable @communicationType is available everywhere
Variable names can include:
_Do not use spaces or special characters. If you need a variable with an unusual name, wrap it in parentheses.
Example:
$('日本') = 123 // Creating a variable with a Japanese name
$x = $('日本') // $x is now 123 // Accessing a variable with a non-standard name
Sometimes you need to create variable names dynamically during script execution. This is called dynamic name resolution. It's especially useful for complex logic.
Example:
// Create variables named x1, x2, x3
$x1 = "red"
$x2 = "blue"
$x3 = "green"
// Random number from 1 to 3
$n = math.rand(1, 3)
// Build the variable name and get its value
$color = $("x" :: $n) // $color may become "red", "blue", or "green"
Thanks to dynamic evaluation, variables can reference the values of other variables, allowing for complex logical chains.
Example:
$x = "y" // $x contains the name of variable #y
#y = "communicationType" // #y contains the name of the global variable communicationType
$communicationType = @#$x // Final value: @communicationType
$) — use them for temporary operations within a single flow.#) — use them to share data across flows in the same module.@) — use them to access general information about the bot’s operation.