Skip to contentSkip to Content

Functions

FUNCTION defines a named, reusable block; call it later with name():

functions.mantis
1REM Set natural typing speed
2SET_SPEED $Human
3
4FUNCTION open_run()
5 GUI r
6 DELAY 500
7END_FUNCTION
8
9open_run()
10STRING notepad
11ENTER
12open_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 constants
2DEFINE #APP STR notepad
3DEFINE #WAIT_TIME INT 500

Rules the compiler enforces

  • Names are case-sensitive identifiers (letters, digits, underscores) and can’t reuse a reserved command or key name.
  • Every FUNCTION needs a matching END_FUNCTION. A stray END_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