Aego Русский

Types

Type Description
bool true / false
int signed 64-bit; wraps on overflow
float IEEE float32
string immutable UTF-8; + concatenation, comparison, len in bytes; no indexing
Vec2 Vec3 Color Quat Rect engine value types; lanes .X .Y .Z .W, .R .G .B .A, .X .Y .W .H
Transform2D{Position Vec2, Rotation float, Scale Vec2} value struct
Transform3D{Position Vec3, Rotation Quat, Scale Vec3} value struct
NodeRef reference to a node; may be nil
AssetRef<Texture | Scene | Prefab | Mesh> reference to an asset; may be nil
ComponentRef<T> reference to a component on a node; may be nil
ScriptRef<T> reference to an instance of script T; may be nil; fields, plain methods and signals of T
Coroutine handle returned by start; may be nil; methods Stop(), Running() bool
Connection handle returned by Connect; may be nil; methods Disconnect(), Connected() bool
Curve read-only view of a curve field of a component (fader.Alpha); evaluated with aego/curve
tween.Tween, timer.Timer, … host handles returned by engine and native modules; may be nil; methods come from the module
struct package-level, value semantics, copied on assignment
enum package-level, int-backed, members State.Idle
[]T growable slice on the VM heap

Rules:

Run it:

package demo

import "aego/log"

type Stats struct {
    Hp    int
    Armor float
}

enum Mood {
    Calm
    Angry
}

script Types {
    var conn Connection

    func Ready() {
        a := Stats{Hp: 10, Armor: 0.5}
        b := a
        b.Hp = 3
        log.Info("structs copy: a.Hp " + string(a.Hp) + ", b.Hp " + string(b.Hp))

        f := 7.9
        log.Info("int(7.9) = " + string(int(f)) + ", float(7) / 2 = " + string(float(7) / 2) + ", 7 / 2 = " + string(7 / 2))

        m := Mood(1)
        log.Info("Mood(1) is Angry: " + string(m == Mood.Angry) + ", int " + string(int(m)))

        v := Vec2{3, 4} * 2 - Vec2{1, 1}
        c := Color{1, 0.5, 0, 1}
        log.Info("vector " + string(v.X) + ", " + string(v.Y) + ", color green " + string(c.G))

        var hits []int
        hits = append(hits, 5)
        hits = append(hits, 7)
        log.Info("slice of " + string(len(hits)) + ", last " + string(hits[len(hits) - 1]))

        log.Info("nil connection connected: " + string(conn.Connected()))
    }
}