Skip to main content
Hooks are the foundation of RollingQuest scripting. When the game detects an event — the level starting, the ball rolling onto a block, an enemy dying — it looks for a matching global function in your script and calls it automatically. You don’t register listeners or subscribe to events; you simply define the function with the right name, and the game does the rest.

What Is a Hook?

A hook is a global Lua function whose name matches one of the game’s predefined event names. The game calls your function when the corresponding event fires, passing in contextual data as parameters. For example, a Level script that prints a message when play begins looks like this:
The function name OnStart is the hook name. The game recognises it and calls it at the right moment.

The self Parameter

Every hook receives self as its first argument. The value of self depends on which entity type the script is attached to: Use self to read properties of the entity and call methods on it from within the hook.

Hooks by Entity Type

Level Hooks

Hooks available in a script attached to the level itself.

Ball Hooks

Hooks available in a script attached to a ball entity.

Block Hooks

Hooks available in a script attached to a block entity.

Side Hooks

Hooks available in a script attached to a side (one face of a block).

Item Hooks

Hooks available in a script attached to an item entity.

Enemy Hooks

Hooks available in a script attached to an enemy entity.

Special Hooks

SpawnCondition

SpawnCondition is a hook that applies to Block, Item, and Enemy scripts. The game calls it before the entity is placed in the level, and your return value decides whether the entity actually appears. Return true (or nothing) to allow the spawn. Return false to suppress it.
SpawnCondition is called very early in level setup. Avoid referencing other entities that may not exist yet.

OnCustomEvent

OnCustomEvent is available on Block, Side, Item, and Enemy scripts. It fires when a concrete sub-class of the parent entity emits one of its own built-in events — for example, a SideButton emits a pressed event when the ball rolls over it, and a BlockBreaking emits break when it shatters. The event set is fixed per sub-class. The base Block, Side, Item, and Enemy types themselves emit no custom events; only their typed sub-classes do. Inside the hook, inspect the CustomEvent argument to dispatch on event name and read any parameters the sub-class sent with it.

CustomEvent shape

Signature

Events emitted by Block sub-classes

Events emitted by Side sub-classes

Events emitted by Item sub-classes

Events emitted by Enemy sub-classes

The base Enemy hook supports OnCustomEvent, but none of the built-in Enemy sub-classes currently emit custom events.

Complete Example

Below is a full Block script that uses four hooks together: it conditionally spawns, sets up state on spawn, reacts to the ball rolling across it, and cleans up when destroyed.
You only need to define the hooks you actually use. The game silently ignores any hook that isn’t present in your script.