Variables
Persistent values shared across steps and threads
Variables persist across steps and are shared with the visual editor's variable panel.
setGlobalVar(name, value)
Sets a named variable. The value is stored as-is — booleans, numbers, strings, and null all retain their type.
| Parameter | Type | Description |
|---|---|---|
name | string | Variable name |
value | any | Value to store. Objects and arrays can be stored and read back within JavaScript, but they are not understood by the visual editor's variable panel or condition steps (which work with strings) and are not persisted between runs. For anything that must cross into the visual layer or survive a run, JSON.stringify it and store the string. |
Returns void
setGlobalVar("counter", 0);
setGlobalVar("flag", true);
setGlobalVar("label", "active");
// Increment — no Number() wrapper needed, type is preserved
setGlobalVar("counter", getGlobalVar("counter") + 1);
getGlobalVar(name)
Gets the value of a named variable, preserving its original type.
| Parameter | Type | Description |
|---|---|---|
name | string | Variable name |
Returns any — the stored value, or undefined if the variable has not been set
var count = getGlobalVar("counter"); // already a number
if (count >= 10) {
print("Done");
}
var flag = getGlobalVar("flag"); // already a boolean
if (flag) {
findAndTap("button");
}