Functions
FUNCTION defines a named, reusable block; call it later with name():
functions.mantis
1REM Set natural typing speed2SET_SPEED $Human34FUNCTION open_run()5 GUI r6 DELAY 5007END_FUNCTION89open_run()10STRING notepad11ENTER12open_run()Combining Functions, Conditions, and Constants
You can fully combine FUNCTION blocks with DEFINE constants and IF conditions to create complex, state-aware payloads. The compiler will inline your constants, validate your function calls, and enforce logic flow.
advanced.mantis
1REM Define reusable constants2DEFINE #APP STR notepad3DEFINE #WAIT_TIME INT 500Rules the compiler enforces
- Names are case-sensitive identifiers (letters, digits, underscores) and can’t reuse a reserved command or key name.
- Every
FUNCTIONneeds a matchingEND_FUNCTION. A strayEND_FUNCTION, a duplicate name, or a definition nested inside another function is a compile error. - A function may call other functions, including ones defined later in the file or each other (mutual recursion). Call depth is bounded on the device — 8 levels deep — so a runaway recursive script is skipped safely rather than crashing the device.
Note:
Functions are also a flash-efficiency tool: a function’s body is stored once no matter how many times it’s called. See Best practices and the flash variants table for how script size maps to storage.
Last updated on