Skip to content

Latest commit

 

History

History
48 lines (34 loc) · 940 Bytes

File metadata and controls

48 lines (34 loc) · 940 Bytes

Struct

struct (structures) are custom data types that allow grouping several variables (fields) under a single name. They are simpler than classes as they do not support constructors, methods, or operator overloading.

Basic Syntax

struct MyStruct {
    field1: Type,
    field2: Type
}

Instantiation

To create an instance of a struct, declare a variable with the struct name as the initial value. All fields are initialized to their default value (as defined in the declaration or null).

var instance = MyStruct;

Accessing Fields

Fields of a struct are accessed using the dot operator ..

instance.field1 = value;
print(instance.field1);

Example

struct Vector2 {
    x: Number,
    y: Number
}

# Create an instance from the Struct
var v = Vector2;

# Assign values
v.x = 10.5;
v.y = 20.0;

# Access values
print("Vector: (" + v.x + ", " + v.y + ")");