//

Common Mistakes

Four mistakes cause most "my detection script does nothing" reports.

1. Not null-checking the result

find, findAll (per element), waitFor, intercept, follow, findText, waitForText, readText, lastMatch, and every Screen.* equivalent return null when nothing matched. Reading .x off null throws TypeError: cannot read property 'x' of null and stops the script dead.

// Crashes the moment the image isn't on screen let match = region.find("reward_button"); click(match.x, match.y); // Always guard let match = region.find("reward_button"); if (match) { click(match.x, match.y); } else { toast("Not found"); }

2. Using a variable name you never declared

There is no implicit m, match, or result global. The variable is only what you named it. Reading a different name throws ReferenceError: m is not defined.

// ReferenceError, you declared "match", not "m" let match = region.find("reward_button"); toast(m.x); // Correct let match = region.find("reward_button"); if (match) toast("x: " + match.x + " y: " + match.y);

The only way to read a previous detection action's result is lastMatch(), and that returns null too when nothing has matched yet.

3. A template name that doesn't exist

The template string must be the real name of a template saved in the macro (or a hex color like "#5FCB4D", or a Color object). A placeholder such as "image" never resolves and silently never matches, check the execution log, which prints Reason: template could not be resolved as a warning in that case.

4. A misspelt option key

Options are a plain object, so a typo is just an extra key that nothing reads, and the call quietly uses its default. region.find("btn", { timout: 500 }) waits the full 5 seconds, not 500ms. The execution log warns when an option key looks like a typo of a real one, but check the spelling yourself:

// Silently uses the 5s default and the 0.8 default score region.find("btn", { timout: 500, minScoer: 0.95 }); // Correct region.find("btn", { timeout: 500, minScore: 0.95 });

Also worth knowing

  • A minScore below the 0.8 default trades misses for false positives. If you loosen it, read match.score to confirm you got the target you meant.
  • readText() returns a plain string, not a match object, readText().text will crash.
  • Variables from the macro editor (getVar) are almost always strings. Convert with Num.parseInt(...) before doing math.
  • Http.get() and Http.post() return only the response body, so a 404 error page looks exactly like success. Use Http.request(url) and check res.ok / res.status when it matters.
  • File.* calls return an empty string or false when a path is outside the script sandbox (File.getFilesDir() and File.getExternalFilesDir()). The reason is written to the script console.