Structs
struct declares a named composite type — a fixed set of typed fields. Declarations live at the top level, like functions.
struct Player {
x: i32
y: i32
big: bool
name: u8[8]
}Declaration is initialization
var p: Player zero-fills every field (numbers → 0, bool → false); array fields get their declared size, zero-filled. There is no constructor and no struct literal — you declare, then assign fields.
server {
var p: Player
event tick(n: i32) {
p.x = 100
p.big = true
p.name[0] = 77
}
}Field access
Use .. Compound assignment works on fields exactly as on variables.
p.x += 1Rules
Array fields must be sized (
name: u8[8]) — a struct's footprint is fixed at compile time.Structs are references. Assigning one struct variable to another aliases the same data; mutations through either name are visible through both.
munosvar a: Player var b = a // b aliases a b.x = 5 // a.x is now 5 tooNo struct duplication via
copy.copy()accepts arrays and strings only. To duplicate a struct, copy its fields one by one.No struct equality. Comparing two structs with
==is a compile error; compare the fields you care about.
When to use a struct vs. parallel arrays
- A struct models one record with named fields.
- Parallel arrays (
playerX[i],playerY[i], …) model a collection of records keyed by an index — the standard pattern for per-player state. See Arrays.