One of the most powerful concepts in G.js — and in Geometry Dash level programming in general — is the trigger function: a self-contained group of GD triggers that can be spawned on demand, delayed, looped, or remapped. Understanding trigger functions and the context system they rely on is the key to writing reusable, composable level logic.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.
What Is a Trigger Function?
In GD, a “trigger function” is a group ID whose spawn trigger chain encodes a sequence of effects. Calling the group fires the entire sequence. G.js automates the bookkeeping — assigning IDs, chaining spawn triggers, tracking delays — so you can write sequential logic as ordinary JavaScript code.TriggerFunctionGroup.
trigger_function(cb) and TriggerFunctionGroup
| Member | Description |
|---|---|
value | The underlying GD group ID. |
call(delay?) | Emits a Spawn trigger that fires the function. Pass a number to add a spawn delay in seconds. |
remap(...args) | Creates a remapped variant of the trigger function with different group IDs substituted. |
stop() | Emits a Stop trigger targeting this function’s group. |
wait(time) — Sequencing Inside Trigger Functions
wait(time) pauses the trigger sequence for time seconds by inserting spawn delay bookkeeping. It can only be called inside a trigger function callback.
Contexts and Why They Matter
G.js assigns triggers to contexts — named containers that correspond to GD group IDs. When a trigger function runs, eachwait() or move trigger that takes time causes G.js to advance to a new context so that subsequent triggers get the correct spawn delay.
This means that after a wait(), the “current group” is no longer the original group of the trigger function. If you try to call the trigger function’s own group to loop it, you need to capture the original group before any context changes occur.
$.trigger_fn_context() — Capturing the Original Group
$.trigger_fn_context() at the very start of a trigger function — before any wait() or timed operations — to store a reference to the trigger function’s original group. You can then call that group later to loop back to the beginning.
ignore_context_change(fn) — Side Effects Without Context Drift
Sometimes you want to trigger a side effect — a flash, a sound, a camera shake — in the middle of a sequence without letting it affect the context used by the surrounding triggers. ignore_context_change runs a function while freezing the current context:
ignore_context_change, the color trigger inside the callback would be placed on the current context and could interfere with spawn-delay calculations.
Full Moveloop Example (from the README)
Here is the complete example from the G.js README demonstrating all of the above concepts together:extend_trigger_func(t, cb) — Extending Existing Functions
You can append additional triggers to a trigger function after it has been created using extend_trigger_func. The callback receives the original context group.
$.extend_trigger_func(t, cb).
blocking_trigger_fn(func) — Blocking Execution
A blocking trigger function is a special trigger function that prevents other triggers from running until it has finished. It is useful for operations that must complete fully before the level can proceed.
stop_exec function. Call stop_exec() at the point where blocking should end — this allows you to unblock early rather than waiting for the entire function to complete.
The Context Class
G.js exposes the Context class for advanced use cases where you need to inspect or manually switch the active context.
| Member | Description |
|---|---|
Context.current | The name of the context that triggers are currently being added to. |
Context.set(name) | Switches the active context by name or group value. |
Context.findByGroup(g) | Returns the Context object that owns the given group. |
Context.link(ctx, parent) | Marks ctx as a child of parent, used to track trigger function hierarchies. |
Quick Reference
| Function | Purpose |
|---|---|
trigger_function(cb) | Create a callable group of triggers |
wait(time) | Advance the context by time seconds |
$.trigger_fn_context() | Get the original group of the current trigger function |
ignore_context_change(fn) | Run side-effect triggers without changing context |
extend_trigger_func(t, cb) | Append triggers to an existing trigger function |
blocking_trigger_fn(func) | Create a trigger function that blocks until stop_exec() is called |
Export Modes
Configure how G.js exports your level to Geometry Dash.
Control Flow Guide
Loops, conditions, and sequencing patterns built on trigger functions.