///
Code action overview

Code

The Code action opens a code editor where you write GScript for logic that is awkward to build out of visual blocks.

Editor Features

  • AI Code Generator (Premium users only): Tap the sparkle icon icon to have AI write or fix code for you.
  • Problems: lists issues the editor finds as you type, such as a name that does not exist in the API. An empty list does not guarantee the script works.
  • Find and replace: search the script, step through matches, and replace one or all. Case sensitivity is a toggle.
  • Format and Wrap tidy the indentation and control whether long lines wrap or scroll.
  • Region Helper: Capture on-screen coordinates and paste them into your code.
  • Global Functions: Functions declared here using fun or function can be called from anywhere in your macro.

Variables

  • Macro Variables: Use setVar("name", value) to save data for visual blocks, and getVar("name") to read it.
  • Local Variables: Use let or const for temporary data that doesn't need to leave the script.

A working example

This reads a counter off the screen, decides what to do with it, and hands the answer back to the visual blocks:

// A global function, callable from any other Code action in this macro function isLow(value) { return value < 10; } let panel = new Region(0, 100, Screen.getWidth(), 200); let text = panel.readText({ readNumbersOnly: true }); let count = Num.parseInt(text, 0); if (isLow(count)) { setVar("needsRefill", true); toast("Only " + count + " left"); } else { setVar("needsRefill", false); }

A can then branch on %needsRefill%, which is the usual pattern: do the awkward part in code, keep the flow visual.

Learn more about GScript .