Skip to content

Objects

Objects are instances created from classes.

An object allows you to access class variables and functions.


Creating an Object

Use Inst to create an object from a class.

Inst example : myclass();

This creates a new object named example.


Accessing Variables

Use the dot (.) operator to access object variables.

DisplayLog(example.x);

Output:

100

Updating Variables

You can modify variables after the object is created.

example.x += 200;

Now the value becomes:

300

Calling Functions

Use the dot (.) operator to call object functions.

example.execute();

Output:

hello world 300

Complete Example

class myclass {
    Int x : 100;

    func execute(){
        DisplayLog("hello world " + x);
    }
}

Inst example : myclass();

example.x += 200;
example.execute();

Output:

object example


Multiple Objects

Each object has its own values.

Inst a : myclass();
Inst b : myclass();

a.x = 10;
b.x = 50;

In this case:

  • a.x = 10
  • b.x = 50

They are independent.


Notes

Warning

You cannot access a class variable directly without creating an object.