Skip to main content
The Level namespace is your primary interface to everything happening inside a running level. Every variable and function documented here is accessed directly as a field on the global Level table — for example, Level.keysCount or Level.completeLevel(). All variables are read-only unless explicitly noted otherwise.

Campaign Info

These variables describe which campaign, episode, and level is currently running. They are useful for conditional logic that should behave differently depending on where in the campaign the player is.

Level State

These variables expose the current structural state of the level — how many keys and treasures exist, what blocks are visitable, and whether all objectives are met.

Time & Timer

These variables let you read and react to the level’s time configuration, including hourglass state.

Scoring

Use these variables to read and react to the player’s current score and how much treasure they have collected.

Lives


Special States


Entity Accessors

These functions return entities from within the level. Functions whose names end with Iterator return a lazy iterator you use in a for loop; their counterparts without that suffix return a plain Lua table.

Main section — iterators

Main section — tables

All sections — iterators

All sections — tables

Single entity lookups


Level Control Functions

These functions change the progression state of the level.

completeLevel

Marks the level as successfully completed and advances to the next level.
Pass nextLevel as the name of a specific campaign level to override the default progression.

loseLevel

Triggers the lose-level state with a specified cause.
Pass a LostLevelCause enum value for built-in cause icons, or pass a plain string for a custom cause message. Use the two-argument form to pair a custom text message with an icon.

restartLevel

Restarts the current level from the beginning.

Time Functions

These functions modify the hourglass countdown at runtime.
invertHourglass() flips the hourglass direction — a countdown becomes a count-up and vice versa.

Scoring & Lives Functions


Effect Functions

Dark mode

Sleeping pill

Checkpoints

Passing a Side saves the checkpoint relative to a specific block face rather than the ball’s current position.

Fruit Helpers


Utility

delayAction

Schedules a Lua function to run after delayTime seconds.

createProjectile

Spawns a projectile in the level. You can target a specific section or default to the main section, and supply either a ProjectileRequest object or a raw property table.

getAvailableProjectileSkins

Returns a table of skin name strings available in the given section (or the main section when called with no arguments).

Cast Functions

These functions attempt to cast the current Level entity to a specific element type. They throw an error if the cast is invalid — use them only when you are certain of the entity’s type.

Usage Example