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.
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.
mainkeywordRuns repeatedly for active script behavior.
initkeywordRuns once for initialization.
get_rtimefunctionReturns 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
Author timed first-level combo steps with legal wait durations and compose sequences with combo-only call.
Input and outputController input and output functionsRead current, physical, and prior values; detect transitions; write outputs; and understand when script changes affect later reads.
Device APIsDevice and runtime functionsUse the verified runtime, slot, control-button, VM timing, polar output, Zen LED, and clamp device APIs.