SplitScript reference / Language / conditional fields
conditional fields
declaration
let shape: Shape; state Provider { if shape == Shape.Variant { ... } else { ... } }
Declares fields whose availability follows an ordinary enum value.
A bare enum global assigned on every successful onAttach path is an attachment-scoped shape discriminator. It is frozen after attachment and can guard conditional fields in both state and managed class declarations. The Unity provider can initialize such a global automatically when the active managed metadata uniquely identifies one variant; otherwise onAttach assigns it explicitly. An enum-valued state field can instead describe a shape that changes while attached. The compiler tracks either kind through if / else if / else, direct match, and is conditions. Compatible fields present with the same type in every possible branch form the common snapshot interface. Other fields are available only where their predicate has been proven. Dynamic branch transitions are transactional: newly active fields must all read successfully, and their first accepted values seed old and current equally.
Examples
Select and refine a supported build shape
if build == Build.Steam {
level: u32 at 0x1000;
checkpoint: u8 at 0x1100;
} else {
level: u32 at 0x2000;
checkpoint: u16 at 0x2100;
}
Refine managed fields with the shared discriminator
if edition == Edition.BaseGame {
print(manager.level else 0)
} else {
print(manager.scene else 0)
}