Variables

Run-scoped values shared across steps and threads

Variables are shared across steps, threads and macros called with callMacro during a run, and with the visual editor's variable panel. They do not survive the run: at the start of every run the table is reset to the macro's declared variables, so nothing a previous run wrote is still there. Use storage for values that must persist.

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
valueanyValue to store. Objects and arrays round-trip within JavaScript, but the visual editor's variable panel and condition steps work with strings — JSON.stringify complex values to share them with the visual layer.

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 a nullish value (null/undefined) if the variable has not been set; test with == null before using it.

var count = getGlobalVar("counter"); // already a number
if (count >= 10) {
  print("Done");
}

var flag = getGlobalVar("flag"); // already a boolean
if (flag) {
  findAndTap("button");
}