Skip to content

Tutorials: Static vs Non‐static

nova ✩ edited this page Jul 14, 2026 · 15 revisions

To interact with our classes so far we have needed to create an instance of it first. It's also possible to create methods and fields that are independent of any instance, similar to a global variable or function, using the static modifier.

class Example:
    public static exampleField: number
    public static exampleMethod():
        broadcast "i dont belong to any instance!"

To access a static field/method you need to refer to the class directly as they are not accessible from any particular instance.

set Example::exampleField to 1
Example::exampleMethod()

Static fields/methods may also be private; the self expression does not apply here so we use the class name.

class Example:
    private static exampleField: string
    public static setField(value: string):
        set Example::exampleField to {_value}

Clone this wiki locally