Skip to main content

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.

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 from 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 resulting GJsObject.
import { spawn_trigger, group } from 'geometry-dash-gjs';

// Immediately spawn group 5
spawn_trigger(group(5)).add();

// Spawn group 5 after 2 seconds
spawn_trigger(group(5), 2).add();
group
any
required
The group to be spawned when the trigger activates.
time
number
default:"0"
Delay in seconds before the group is spawned.
Returns GJsObject — call .add() to place it in the level.

call_with_delay

Calls a group or trigger function after the specified number of seconds. Unlike spawn_trigger, this does not return an object; the spawn trigger is added automatically.
import { call_with_delay, trigger_function } from 'geometry-dash-gjs';

const myFunc = trigger_function(() => {
  // triggers placed here run after the delay
});

call_with_delay(1.5, myFunc);
time
number
required
Delay in seconds before the group is called.
func
any
required
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].
import { for_loop } from 'geometry-dash-gjs';

// Call the function 5 times with a 0.1-second gap
for_loop([0, 5], (i) => {
  // `i` is the current iteration index
}, 0.1);
rang
any[]
required
A two-element array [start, end] defining the iteration range.
fn
Function
required
The function to execute on each iteration. Receives the current index as its argument.
delay
number
default:"0.05"
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 a TriggerFunctionGroup whose .stop() method halts the loop.
import { frame_loop, trigger_function } from 'geometry-dash-gjs';

const tick = trigger_function(() => {
  // runs every tick
});

const loop = frame_loop(tick);

// Stop the loop later
loop.stop();
tfn
any
required
The group or trigger function to call each tick.
Returns 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.
import { trigger_function, frames } from 'geometry-dash-gjs';

trigger_function(() => {
  // do something
  frames(10); // wait 10 ticks (~41.7 ms)
  // do something else
});
frames_count
number
required
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

Like frame_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.
import { render_frame_loop, trigger_function } from 'geometry-dash-gjs';

const draw = trigger_function(() => {
  // runs every render frame
});

const loop = render_frame_loop(draw);
loop.stop(); // halt when done
fn
any
required
The group or trigger function to call each render frame.
Returns TriggerFunctionGroup.

render_frames

Pauses execution for the given number of render frames. Render frames are variable (unlike the fixed 1/240 s game tick).
import { trigger_function, render_frames } from 'geometry-dash-gjs';

trigger_function(() => {
  render_frames(3); // wait 3 render frames
});
frames_count
number
required
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 constantValueBehaviour
MODE_STOP0Stops after the last entry (default)
MODE_LOOP1Loops back to the first entry
MODE_LAST2Keeps calling the last entry
import {
  sequence, trigger_function, group,
  MODE_LOOP
} from 'geometry-dash-gjs';

const a = trigger_function(() => { /* step 1 */ });
const b = trigger_function(() => { /* step 2 */ });
const c = trigger_function(() => { /* step 3 */ });

const step = sequence(
  [[a, 0], [b, 0], [c, 0]],
  MODE_LOOP // loop back after step 3
);

// Call step() each time you want to advance
step();
sequence_arr
any[]
required
Array of [group, delay] pairs. Example: [[group(1), 1], [group(2), 0.5]].
mode
number
default:"0"
Sequence mode. 0 = stop, 1 = loop, 2 = last. Use the exported MODE_STOP, MODE_LOOP, MODE_LAST constants.
min_int
number
default:"0"
MinInt value passed to the underlying sequence trigger.
reset
number
default:"0"
Reset mode. 0 = full reset, 1 = step reset.
Returns () => 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.
import { remappable, counter } from 'geometry-dash-gjs';

const c1 = counter(0);
const c2 = counter(10);

const addFive = remappable((item) => {
  // `item` is the remapped item ID
  item.add(5);
});

// Call the remappable with a specific counter's item ID
addFive(c1.item);
addFive(c2.item);
fn
Function
required
The function body. It receives the remapped arguments at call time.
Returns (...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 with while_loop and similar condition-based functions.
import { counter, equal_to, while_loop } from 'geometry-dash-gjs';

const c = counter(0);
while_loop(equal_to(c, 10), () => {
  c.add(1);
});
count_obj
Counter
required
The counter to compare.
other
number
required
The number to compare the counter against.
Returns a condition object { count, comparison, other }.

less_than

Returns a condition object asserting that a counter is less than a given number.
import { counter, less_than, while_loop, trigger_function } from 'geometry-dash-gjs';

const c = counter(0);
const body = trigger_function(() => { c.add(1); });

while_loop(less_than(c, 5), body);
count_obj
Counter
required
The counter to compare.
other
number
required
The upper bound (exclusive).
Returns a condition object { count, comparison, other }.

greater_than

Returns a condition object asserting that a counter is greater than a given number.
import { counter, greater_than, while_loop, trigger_function } from 'geometry-dash-gjs';

const c = counter(100);
const body = trigger_function(() => { c.subtract(1); });

while_loop(greater_than(c, 0), body);
count_obj
Counter
required
The counter to compare.
other
number
required
The lower bound (exclusive).
Returns a condition object { count, comparison, other }.

while_loop

Repeatedly calls triggerFunction for as long as the given condition holds. The loop checks the condition before each execution and stops when it is no longer true.
import { counter, while_loop, less_than, trigger_function } from 'geometry-dash-gjs';

const c = counter(0);

while_loop(less_than(c, 10), trigger_function(() => {
  c.add(1);
}));
r
object
required
A condition object returned by equal_to, less_than, or greater_than.
triggerFunction
any
required
The trigger function or group to call on each iteration.
del
number
default:"0.05"
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.
import { trigger_function, wait } from 'geometry-dash-gjs';

trigger_function(() => {
  // do A
  wait(2); // pause for 2 seconds
  // do B
});
time
number
required
Seconds to wait before continuing execution.
Use wait for second-precision delays, frames for tick-precision delays, and render_frames for render-frame-precision delays.

Build docs developers (and LLMs) love