Skip to main content

Methods

It can helpful for top level declarations to define methods. These can be used either as helpers or as an interface that can be extruded.

Methods can be defined with any signature you like. By default they are public and can be extruded. Methods are available within other methods as well, and can be sourced with a from mapping or defined in the template definition itself.

Methods can be marked with :private to prevent them being used in extrusions.


template MethodExample : SomeCompanionType {

// when defining a method from a companion type you must define the signature explicitly
// and it must exactly match the method as it was defined in the companion type
method:private float Sqrt(float input) from $companion;

method float PrintSqrt(float input) {
// using the Sqrt method
Debug.Log(Sqrt(input));
}

method void PrintValue(int value) {
Debug.Log(value);
}

}

template MethodUsage render {

// methods get extruded like normal with the [] operator
MethodExample() [PrintValue, PrintSqrt];

run PrintValue(100);
run PrintValue(200);
run PrintSqrt(300f);

}