Enums
CompilesAn enum gives names to a fixed set of whole numbers. Instead of remembering that state 2 means “cooling
down”, you write PadState::CoolingDown.
enum PadState { Idle Charging CoolingDown = 5}
let mut state: int = 0
fn start_charging() { if state == PadState::Idle { state = PadState::Charging }}- Each name is one option. They count up from
0unless you give a number with=. - Refer to an option as
EnumName::Option. - Options separate by line breaks or commas.
Shipped scripts use enums heavily: k_state_loading, k_state_loaded, and so on. When you inherit a script
(Inheritance) its enums come with it.
For programmers
Enums are named integer constants, not a distinct type: comparisons and assignments are plain int operations,
and nothing stops an out-of-range value. Replicating one efficiently is a separate step
($net.set_field_replicated’s is_enum), covered in Replication.