Use Script Variables
As an application designer or story developer, you use script variables, which are useful for storing intermediate results repeatedly used in a script, for example.
About Script Variables
Script variables are reusable elements that store a value of a certain type, which exist throughout the runtime. The script variables you create in an application or story are available to itself only. You can define their values not only in the application or story, but also in its URL by adding a specific URL parameter.
-
string
Represents text as a sequence of characters.
-
boolean
Represents a logical value, either true or false.
-
number
Represents a floating-point numerical value.
Can be entered in ordinary format or scientific notation format such as 1e+20 or 1e20. If the number is longer than 21 digits, it will be automatically displayed in scientific notation format.
-
integer
Represents a non-fractional numerical value.
Scientific notation format isn't supported for entering values. However, at runrime if the number is longer than 21 digits, it'll be displayed in scientific notation.
In addition to the primitive types described above, you can select a wider variety of non-primitive types for the script variable, such as button, category, chart, clock, data source and table.
Create a Script Variable
Procedure
Define a Script Variable's Value via URL Parameter
You can initialize the application or story based on your needs by simply making some changes to its URL. The value defined in the URL parameter can be passed to the corresponding script variable.
Procedure
Use a Script Variable
You can use a script variable in your script as a local variable. For example, you change the value by assigning a new one and use this value by passing it as argument when calling a function.
If you write scripts in the application or story, you can insert the script variable you've created by selecting it from the value help in the script editor. You can activate the value help at any place in the script by pressing CTRL + Space .
If you need to use the script variable in calculation, you can type @ in the formula in Calculation Editor to insert it. All the available script variables will be automatically displayed in the dropdown list. Note that only global variables of string, integer and number types can be referenced in the calculation editor, while the array type isn't supported.
if (ScriptVariable_1 = "xxx"; 100 ; -100)
You can also define script variables as the source of dynamic text in a text widget.
Change or Delete a Script Variable
To change an existing scripting variable, select it in the Outline panel. You can see the Scipt Variable panel open again where you can also make the changes there.
To delete an existing scripting variable, choose beside the script variable in the Outline panel, and select Delete.
If the variable’s been used in a calculated measure, you need to modify the calculation first before deleting the variable.