Lynxer

Documentation

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");

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
}

See also