G.js provides a rich set of control-flow primitives that let you schedule trigger execution, loop over sequences, and build parameterized trigger systems. Under the hood each function emits the appropriate GD triggers — spawn triggers, sequence triggers, and item-backed timing — so everything runs inside the game itself with no external runtime required.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/g-js-api/G.js/llms.txt
Use this file to discover all available pages before exploring further.
Spawn Triggers
spawn_trigger(group, time?)
Creates a raw GD spawn trigger and returns it as a GJsObject. You must call .add() on the result to place it in the level.
The group to spawn.
Delay in seconds before the group is spawned.
Most of the time you won’t need
spawn_trigger directly. Use wait(), call_with_delay(), or trigger_function() instead — they manage spawn triggers for you.Delays
wait(time)
Inserts a pause inside the current trigger-function context. All triggers defined after wait() are placed in a new spawn context that fires after the delay.
Duration to wait, in seconds.
call_with_delay(time, func)
Schedules a group or trigger function to be called after time seconds. Unlike wait(), this does not block the current context — it fires func asynchronously.
Delay in seconds.
The group or trigger function to call after the delay.
For Loops
for_loop(range, fn, delay?)
Iterates fn once for each value in range, inserting a small delay between each iteration.
An array of values to iterate over. Use the
range(start, end) helper to generate numeric sequences.Callback called once per iteration with the current value.
Seconds to wait between each iteration.
Frame Loops
Frame loops repeat a trigger function continuously. G.js offers two variants matching GD’s two timing modes.frame_loop(tfn)
Calls tfn every game tick (1/240 second), regardless of frame rate. Returns a TriggerFunctionGroup that you can call .stop() on to halt the loop.
The group to call on every tick.
TriggerFunctionGroup — call .stop() to end the loop.
frames(frames_count)
Waits exactly frames_count ticks (each tick = 1/240 s) inside a trigger-function context.
Number of ticks to wait.
render_frame_loop(fn)
Like frame_loop, but fires on every rendered frame instead of every tick. The interval is variable and depends on the player’s FPS setting. Returns a TriggerFunctionGroup.
render_frames(frames_count)
Waits frames_count rendered frames inside a trigger-function context.
Use
frames() / frame_loop() for deterministic gameplay logic. Use render_frames() / render_frame_loop() only for cosmetic effects where exact timing doesn’t matter, since the interval varies with the player’s device.Sequence Triggers
sequence(sequence_arr, mode?, min_int?, reset?)
Wraps GD’s Sequence trigger. Each call to the returned step function advances through the list, calling the next group in the array.
Array of
[group, weight] pairs. Each pair calls group when that step is reached. The weight field matches GD’s internal sequence weight property.What to do when the sequence reaches the end:
MODE_STOP(0) — stop at the last item.MODE_LOOP(1) — wrap back to the first item.MODE_LAST(2) — keep repeating the last item.
Minimum interval between steps (maps to GD’s MinInt field).
Reset behaviour:
0 = full reset, 1 = step reset.() => void. Call it to advance to the next item in the sequence.
Sequence Mode Constants
| Constant | Value | Behaviour |
|---|---|---|
MODE_STOP | 0 | Halts at the last step. |
MODE_LOOP | 1 | Wraps around to the beginning. |
MODE_LAST | 2 | Repeats the final step indefinitely. |
Remappable Trigger Functions
remappable(fn)
Creates a trigger-function-like system whose internal item IDs can be remapped at call-time. This is the G.js equivalent of parameterized trigger functions — you describe a template once and call it with different arguments.
A function whose parameters become remappable item IDs. Inside
fn, use the parameter values as group/item IDs.When to Use Which Abstraction
| Tool | Runs at | Best for |
|---|---|---|
trigger_function | Play-time | Standard trigger groups; most use-cases. |
remappable | Play-time | Reusing trigger sequences with different IDs. |
sequence | Play-time | Step-by-step progressions (cutscenes, puzzles). |
for_loop | Build-time | Generating repeated trigger patterns. |
frame_loop | Play-time | Per-tick gameplay logic. |
render_frame_loop | Play-time | Per-frame cosmetic effects. |
Full Examples
for_loop — Staggered Group Calls
frame_loop — Counter Incrementer
sequence with MODE_STOP
remappable — Generic Move Routine
Events
Combine control-flow with event listeners for reactive logic.
Counters
Use counters inside loops and sequences.
Control Flow API
Full API reference for all control-flow functions.
Trigger Functions
How trigger functions and contexts work under the hood.