Enum in Verse
Enum
Enum is short for enumeration, which means to name or list a series of things, called enumerators. This is a type in Verse that can be used for things like days of the week or compass directions.
Enum is short for enumeration, which means to name or list a series of things, called enumerators. This is a type in Verse that can be used for things like days of the week or compass directions.
Click image to enlarge.
direction := enum{Up, Down, Left, Right} Copy full snippet |
Creating an enum: Use the keyword enum followed by {}. If you want to specify initial elements in the enum, add the enumerators between the {}, separated by ,. |
|---|---|
direction.Up Copy full snippet |
Accessing an enumerator: Use . on the enum, followed by the enumerator you want to use. For example direction.Up. |
Persistable Type
An enum is persistable when defined with the persistable specifier. This means that you can use them in your module-scoped weak_map variables and have their values persist across game sessions. For more details on persistence in Verse, check out Using Persistable Data in Verse.
The following is an example of a persistable enum for the days of the week that can be stored, updated, and accessed later for a player.
| | day := enum<persistable>: |
| --- | --- |
| | Monday |
| | Tuesday |
| | Wednesday |
| | Thursday |
| | Friday |
| | Saturday |
| | Sunday |
Copy full snippet
