Tips
Practical advice for writing reliable scripts
- Coordinates are in physical screen pixels. Use
tapAt(x, y)when you know exact positions,findAndTapwhen you want image-based matching, andtapAt("name")to tap an object's stored center without searching. - Coordinate convention:
Regionobjects always use the top-left corner and operate in current screen pixel space.Matchobjects returned by search functions expose bothcx/cy(center) andx/y/w/h(bounding box, top-left origin) — sinceMatchextendsRegion, you can chain further searches directly on a match result. - Coordinate portability: raw coordinates (
tapAt(x, y),swipe,longPress) are device-specific — they hit the same pixel regardless of screen size or density, which is rarely the right position on another device. Apps also don't scale their UI elements proportionally to resolution, so no coordinate-scaling formula is reliably accurate. For macros you intend to share, prefer image-matching (findAndTap,getPosition) or named objects (tapAt("name")). findText("x")is a shortcut forfindAllText("x")[0] ?? null— use it when you only need the first match.getGlobalVarreturns the value with its original type — noNumber()orString()wrapper needed. Objects and arrays must be stored viaJSON.stringifyand parsed back withJSON.parse.findAllTextandgetPositionsserve the same looping purpose but use different detection methods: OCR vs. image template matching.getPosition()andocr()can be combined freely:if (getPosition("a") !== null && ocr("b") === "ready").- Standard JS built-ins (
Math,Date,JSON,Array, …) are fully available. - Use
spawnThreadto separate vision work (slow, ~100–200 ms) from motor control (fast, ~20 ms) — the background thread updates globals, the main thread reads and acts.