Skip to main content
The Level namespace is the central hub for changing what happens in a running level. You can end the level in any outcome, adjust the player’s lives and score, stretch or shrink the time on the hourglass, flip the lights off, freeze the ball with a sleeping pill effect, and save progress to a checkpoint — all from a Lua script.

Winning, Losing, and Restarting

Three functions control the top-level outcome of a level at any point during play.

The LostLevelCause Enum

Pass one of these values to Level.loseLevel (or Ball:kill / Ball:instaKill) to set the death icon shown on screen.

Lives

Read and modify the player’s life count at runtime.
Level.hasInfiniteLives is writable — set it to true to give the player infinite lives for the duration of a scripted sequence (for example, a puzzle section where dying should not be permanent).

Score

Award or inspect score values during play.

Hourglass Timer

The hourglass counts down from a set amount; when it reaches zero it can cause the player to lose the level. You can manipulate it at any time.
Level.invertHourglass() flips the hourglass state — if it was counting down it now counts up, and vice versa.

Dark Mode

Toggle dark mode to plunge the level into near-darkness, relying on the ball’s own light source.

Checkpoints

Save the current ball position and level state so the player respawns there instead of the start.

Sleeping Pill Effect

The sleeping pill effect temporarily slows or disables the ball’s movement, useful for cut-scenes or scripted pauses.

Delayed Actions

Level.delayAction schedules a function to run after a fixed number of seconds. It is non-blocking — the level continues running while the timer counts down.

Complete Example — Guarded Exit with Score Bonus

This script is attached to the Level entity. It waits for the player to reach the exit block (OnBallRoll on the exit side), checks that all keys are collected, awards a time-based score bonus, then completes the level.
Combine Level.areAllKeysCollected with the OnBallRoll hook on your exit block to build a gated exit without any engine-level exit block settings — pure script control.