In AskiaScript, a declarative variable is a temporary, custom variable created to store and manipulate data temporarily, within a script.
The declarative variable is in the local scope, which means it is available only during the execution of the current condition/action or in the context (label) of the inline script.
Use the dim keyword to declare a variable in AskiaScript, followed by the name of the variable. The name of the variable:
must begin with a letter or underscore ( _ )
may only contain alphanumeric characters and underscores ( _ )
may no contain any spaces
may not already be used in the same scope (i.e. the name must be unique in the same scope)
may not be a reserved keyword or question shortcut
dim my_variable
You can assign a value to a declarative variable using the equals sign (=) (see also topics assignment vs comparison). It is possible to assign a value after or during the declaration of the variable:
dim my_variable my_variable = 1
OR
dim my_variable = 1
Unless the type of the variable is specified, the first assignment of the variable determines its final type; the type of the variable cannot be changed during the AskiaScript execution. For example:
dim my_variable = 12 ' => The variable is a number
my_variable = "abc" ' => Try to assign a string in a number variable: raises an exception
Exceptions occur if you attempt to: