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.

ParameterTypeDescription
namestringVariable name
valueboolean | number | string | nullValue to store. Objects and arrays are not supported; use JSON.stringify to store them as strings.

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.

ParameterTypeDescription
namestringVariable 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");
}