Control flow
Mantis executes scripts top to bottom, but provides robust control flow mechanisms to handle real-world hardware interactions. You can use conditional logic based on button states, and repeat blocks using loops with precise control.
Conditions
Mantis fully supports conditional branching using IF, THEN, ELSE, and END_IF. The conditionals evaluate runtime hardware states rather than computed data.
Available condition evaluators are:
BUTTON_PRESSED— True if the physical Upload button is currently held down.BUTTON_RELEASED— True if the physical Upload button is currently released.TRUE— Always true.FALSE— Always false.
Basic IF / THEN
1REM Set a natural typing speed2SET_SPEED $Human34REM Check if the button is held5IF BUTTON_PRESSED THEN6STRINGLN The button is currently held down!7END_IFIF / ELSE
1REM Set a natural typing speed2SET_SPEED $Human34REM Branch based on the button state5IF BUTTON_PRESSED THEN6STRINGLN Holding the button!7ELSE8STRINGLN Button is not held.9END_IFAdditionally, there are two event-driven commands tied to the button:
WAIT_FOR_BUTTON_PRESS— pauses the whole script until the button is physically pressed, then continues.BUTTON_DEF … END_BUTTON— defines a handler that runs whenever the button is pressed during execution.
Loops
LOOP repeats a block of commands. Close it with END_LOOP:
1REM Set natural typing speed2SET_SPEED $Human34LOOP5STRING .6DELAY 5007END_LOOPWritten bare, or as LOOP TRUE, the block repeats forever.
Mantis also supports counted loops, which will run a finite number of times. The maximum loop nesting depth (MAX_LOOP_DEPTH) is 8.
1REM Set natural typing speed2SET_SPEED $Human34LOOP 55STRINGLN This will print exactly five times.6DELAY 1007END_LOOPLoop Control (BREAK / CONTINUE)
You can exit a loop early or skip to the next iteration using BREAK and CONTINUE. These apply to the innermost open loop.
1REM Set natural typing speed2SET_SPEED $Human34LOOP5 IF BUTTON_PRESSED THEN6 STRINGLN Button pressed, breaking loop!7 BREAK8 END_IF9 10 STRING .11 DELAY 100012END_LOOP