SplitScript reference / Language / enum
enum
declaration
enum Name[: Integer] { Variant[(Type)] [= value] }
Declares a nominal sum type.
Enums support optional variant payloads, exhaustive match expressions, and structural equality when their payloads support it. Writing a fixed-width integer representation after the name, such as enum GameState: i32, instead declares the enum's process-memory encoding and derives MemoryReadable. Process-readable variants cannot carry payloads. Their discriminants start at zero, increase by one when omitted, and may be written explicitly with = value; duplicates and values outside the representation are compile errors. Reading an unknown raw discriminant fails the enclosing memory read instead of constructing an invalid enum value. The same validation applies recursively inside readable structs and fixed arrays and respects the state provider's byte order.
Examples
Describe distinct states
enum Mode {
Menu,
Playing,
}
Attach data to variants
enum LoadState {
Loading,
Ready(u32),
Failed(String),
}
Read an integer-backed game state
enum GameState: i32 {
Mission = 0,
TitleScreen = 1,
Menu = 2,
}
state "game.exe" {
gameState: GameState at 0x1000
}