Control flow functions let you schedule, repeat, and branch trigger execution inside a G.js level. They cover everything from basic delays to counted loops, tick-level timing, and stateful sequences. Import any of these fromDocumentation 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.
geometry-dash-gjs alongside the rest of the library.
spawn_trigger
Creates a spawn trigger that activates a group after an optional delay and returns the resultingGJsObject.
The group to be spawned when the trigger activates.
Delay in seconds before the group is spawned.
GJsObject — call .add() to place it in the level.
call_with_delay
Calls a group or trigger function after the specified number of seconds. Unlikespawn_trigger, this does not return an object; the spawn trigger is added automatically.
Delay in seconds before the group is called.
The group or trigger function to call after the delay.
for_loop
Repeats a function a specified number of times, optionally with a delay between each cycle. The range is expressed as a two-element array[start, end].
A two-element array
[start, end] defining the iteration range.The function to execute on each iteration. Receives the current index as its argument.
Seconds to wait between each cycle.
frame_loop
Creates a loop that calls a group or trigger function on every game tick (1/240 s). Returns aTriggerFunctionGroup whose .stop() method halts the loop.
The group or trigger function to call each tick.
TriggerFunctionGroup — call .stop() to halt the loop.
frames
Pauses execution inside a trigger function context for the given number of game ticks (each tick = 1/240 s). Must be called inside a trigger function.Number of ticks (1/240 s each) to wait.
Ticks are fixed at 1/240 s regardless of frame rate. Use
render_frames if you need to wait for actual rendered frames instead.render_frame_loop
Likeframe_loop, but fires on every render frame rather than every game tick. Render frames are variable and depend on the player’s frame-rate settings.
The group or trigger function to call each render frame.
TriggerFunctionGroup.
render_frames
Pauses execution for the given number of render frames. Render frames are variable (unlike the fixed 1/240 s game tick).Number of render frames to wait.
sequence
Creates a sequence trigger from an array of[group, delay] pairs and returns a step function. Each time the step function is called, the sequence advances by one entry. The mode parameter controls what happens after the last step.
| Mode constant | Value | Behaviour |
|---|---|---|
MODE_STOP | 0 | Stops after the last entry (default) |
MODE_LOOP | 1 | Loops back to the first entry |
MODE_LAST | 2 | Keeps calling the last entry |
Array of
[group, delay] pairs. Example: [[group(1), 1], [group(2), 0.5]].Sequence mode.
0 = stop, 1 = loop, 2 = last. Use the exported MODE_STOP, MODE_LOOP, MODE_LAST constants.MinInt value passed to the underlying sequence trigger.
Reset mode.
0 = full reset, 1 = step reset.() => any — a step function that advances the sequence once per call.
remappable
Creates a trigger-function-like system that can be called with concrete item IDs at runtime (e.g. a counter’s.item). This is useful when you want to reuse the same trigger logic with different counters.
The function body. It receives the remapped arguments at call time.
(...args: any[]) => void — a callable that forwards its arguments as item IDs into the trigger function.
equal_to
Returns a condition object asserting that a counter equals a given number. Used withwhile_loop and similar condition-based functions.
The counter to compare.
The number to compare the counter against.
{ count, comparison, other }.
less_than
Returns a condition object asserting that a counter is less than a given number.The counter to compare.
The upper bound (exclusive).
{ count, comparison, other }.
greater_than
Returns a condition object asserting that a counter is greater than a given number.The counter to compare.
The lower bound (exclusive).
{ count, comparison, other }.
while_loop
Repeatedly callstriggerFunction for as long as the given condition holds. The loop checks the condition before each execution and stops when it is no longer true.
A condition object returned by
equal_to, less_than, or greater_than.The trigger function or group to call on each iteration.
Delay in seconds between iterations.
wait
Pauses execution inside a trigger function for the specified number of seconds. This is a core function and is available directly from the main import.Seconds to wait before continuing execution.