Global Helpers
These functions and shortcuts are always available at the top level, no object prefix needed.
| Global | What it does |
|---|---|
click(x, y, opts?) | Tap the screen. Accepts coordinates, a Point object, or an options object. |
swipe(x1, y1, x2, y2, opts?) / swipe(path, opts?) | Swipe gesture. Pass a path array for multi-point or hold-and-move gestures. |
wait(ms) / sleep(ms) | Pause execution for a number of milliseconds. sleep is an alias. |
toast(message, durationMs?) | Show a temporary on-screen toast. Default duration is 2000ms. |
log(...) / print(...) | Write a log line. Aliases for console.log. |
wake() | Wake the device screen. |
between(min, max) | Return a random integer in an inclusive range. Global alias for Random.between. |
CenterPoint() | Return { x, y } center of the source screen. |
exists(template, timeout?) | Check whether an image exists on the full screen. No timeout → instant pass. |
lastMatch(detectionId?) | The match a detection action already found, without searching again. Use it in a Code action inside a detection's On Success branch. Returns a Match (no score/template) or null. |
clickText(text, options?) | Global alias for Ui.clickText. |
readText(x, y, w, h, options?) | Global alias for new Region(x, y, w, h).readText(options). |
setVar(name, value) | Write a macro variable. |
getVar(name) | Read a macro variable. |
storeVar(name, value) | Write a macro variable and persist it across macro runs. |
clearStoredVar(name) | Delete a persisted variable. |
callFunction(name, params?) | Run a Function you built in the macro editor by its name (id also works). Pass parameters as an object keyed by the function's parameter names. Returns the function's return value as a string. |
playRecording(name, opts?) | Replay a recording captured with Record Mode. Global alias for Record.play. |
pinchIn(cx, cy, distance?, duration?) | Pinch-in gesture (zoom in). |
pinchOut(cx, cy, distance?, duration?) | Pinch-out gesture (zoom out). |
Example:
wake();
let delay = between(800, 1200); // random ms between 800 and 1200
wait(delay);
let center = CenterPoint();
click(center.x, center.y);
log("Clicked at", center.x, center.y);
sleep(500); // same as wait(500)
// Reuse a Function built in the macro editor
callFunction("Open Inventory");
let gold = callFunction("Get Gold Count"); // returns the function's return value as a stringPlaying a recording:
Record.play(name, opts?) replays a recording made with Record Mode, with the same options as the Recording action. The name is case-insensitive, and an unknown name throws an error listing the available recordings.
Record.play("Open Chest"); // once
Record.play("Open Chest", 3); // a bare number is the repeat count (true = forever)
Record.play("Open Chest", {
repeat: 5, // -1 / "infinite" / true = loop forever
speed: 1.5, // playback speed multiplier
startDelay: 500, // pause before the first step
loopDelay: 250, // pause between repeats
postWait: 1000, // pause after the last repeat
randomization: 4, // +/- px of tap jitter, fresh every repeat
timingVariation: 10, // +/- % on every wait / hold duration
timeLimit: 30000 // stop an infinite repeat after this many ms
});
Record.exists("Open Chest"); // true / false
Record.names(); // ["Open Chest", "Sell Loot"]
Record.list(); // [{ id, name, steps }, ...]Recordings are per-macro, so a script can only play recordings that belong to the macro it runs in. Playback respects Stop and Pause exactly like the RECORDING action, and every option accepts a %variable% token as well as a plain number.
Reading a detection action's match:
Put a Code action in the On Success branch of a detection action and lastMatch() returns what it found. To pass coordinates to later actions, the detection's own Save Result To Variable field is usually simpler:
let m = lastMatch();
if (m) {
setVar("matchX", m.x); // center coordinates of the match
setVar("matchY", m.y);
m.click(); // or just tap it directly
}To keep a match after later detections run, use Save Result To Variable and read it with getVar("name"). It returns the same kind of object (found, x, y, point, region, click()). Check if (m.found), not if (m), because a miss is still an object.
Inside a Multi Detection, lastMatch() in the On Success branch reflects the last detection that ran. To read a specific one, put the Code action in that detection's own On Success branch.
Image, color, text and UI Element actions all set lastMatch(), at any nesting depth and inside called functions. It is null after a "wait until gone" detection or a UI Element waiting to disappear, since nothing was found.
For a UI Element, the match means the element was found, not that the tap worked, so an On Fail branch can still use lastMatch() to retry it.
lastMatch() returns null when nothing has matched yet. It has x/y (centre), cx/cy, point and click(), but no score or template. region can be null (always for text detections and for image detection in click-multiple mode), so check it before use. Use Region.find when you need a score.