ExecutionUpdated 2026-07-24

init and main execution model

Know what runs once, what loops, and why blocking or one-time work belongs in the correct execution block.

Overview

init runs once when the script is initialized. main is the mandatory loop where the virtual machine repeatedly evaluates live input and produces output.

Treat each main pass as a short update. Timed sequences belong in combos, not blocking delays inside main.

Key facts

  • init runs once.
  • main is mandatory and loops.
  • wait cannot be used in main.
  • Input and output are reevaluated during repeated main execution.

GPC syntax examples

Examples are intentionally small. Replace identifiers only with values documented for your target.

One-time state, repeated logicexample.gpc
int ready;

init {
    ready = TRUE;
}

main {
    if (ready && event_press(XB1_A)) {
        combo_run(Tap);
    }
}

combo Tap {
    set_val(XB1_A, 100);
    wait(40);
}

Functions, commands, and terms

Names below are catalog entries, not guessed signatures. Open the official sources for current parameter and return-value details.

NameKindPurpose
mainkeyword

Runs repeatedly for active script behavior.

initkeyword

Runs once for initialization.

get_rtimefunction

Returns elapsed runtime associated with the current VM cycle.

Common mistakes

Expecting init to rerun every loop.

Trying to pause main with wait.

Doing repeated initialization inside main.

Official GPC sources

Use these first-party references to confirm exact syntax and runtime behavior for your installed firmware and Studio version.

Related GPC references