Structs
A struct is a data-only named type: a fixed list of typed fields, constructed positionally with new, with no methods. Declare it between global setup() and global main().
Declaration
struct Player {
int health;
str name;
}
Every field has an explicit type and ends with ;. Fields may not have default values (int health = 100; fails with expected ';' after struct field), and a struct has no methods — use a class when you need either.
Construction
Player first = new Player(100, "Ada");
- Arguments are matched positionally to the declared field order.
- The argument count is checked:
new Player(100)reportsstruct 'Player' expects 2 arguments, received 1. - Each argument is type-checked: a
strwhere anintis expected reportsvalue cannot be assigned to type 'int'.
Access and assignment
Read and write fields with dot access; no type prefix is needed:
println(first.name); // Ada
first.health = 90;
println(first.health); // 90
(That differs from vargroups, whose field assignment requires the type.)
Full example
global setup(){}
struct Player {
int health;
str name;
}
global main(){
Player first = new Player(100, "Ada");
first.health = 90;
println(first.name); // Ada
println(first.health); // 90
}