Skip to content

sonolus.script.globals

level_data(cls: type[T]) -> T

Define level data.

Level data may only be modified during preprocess. Compared to level memory, it enables some optimizations during gameplay, so it's recommended to use it if mutation is only needed during preprocessing.

All level data in a given mode shares a combined limit of 4096 values; exceeding it raises a compilation error.

Usage
@level_data
class LevelData:
    variable: int

variable = level_data(Array[int, Dim[10]])

def f():
    LevelData.variable = 1
    variable[0] = 2

level_memory(cls: type[T]) -> T

Define level memory.

Level memory exists in play, watch, and tutorial mode. Preview mode has no level memory; use level_data there instead.

In those modes, level memory may be read in any callback and modified in play's preprocess, update_sequential and touch, in watch's preprocess and update_sequential, and in tutorial's preprocess, navigate and update.

Compared to level data, it allows modification during gameplay, but prevents some optimizations.

All level memory in a given mode shares a combined limit of 4096 values; exceeding it raises a compilation error.

Usage
@level_memory
class LevelMemory:
    variable: int

variable = level_memory(Array[int, Dim[10]])

def f():
    LevelMemory.variable = 1
    variable[0] = 2