Struct is short for structure, and is a way to group several related variables together. Any variables can be grouped, including variables of different types.
[
Click image to enlarge.
Verse | Creating a struct: Use the keyword |
Verse | Instantiating a struct: You can construct an instance of a struct from an archetype. An archetype defines the values of a struct’s fields. |
Verse | Accessing fields on a struct: You can access a struct’s fields to get their value by adding |
Persistable Type
A struct is persistable when:
Defined with the persistable specifier.
Not parametric.
Only contains members that are also persistable.
When a struct is persistable, it 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.
You cannot alter a persistable struct once you’ve published your island. For this reason, we recommend using persistable structs only when the schema is known to be constant.
The following is an example of a persistable struct X, Y coordinates that can be stored, updated, and accessed later for a player.
coordinates := struct<persistable>:
X:float = 0.0
Y:float = 0.0