In the engineβs scripting system, each object executes its own script file inside a fully isolated environment. This means that any function defined inside the script of an object cannot be called directly from the same object nor from another object.
To ensure safety, modularity and to avoid uncontrolled access, all function calls must be made using the engine method:
CallFunction() β the official method to call functionsMyFunction().CallFunction().
CallFunction() allows you to execute a function from another object's script
safely and in a controlled way.
It can also return values, making it possible to check states, run calculations or validate conditions.
CallFunction(target, "FunctionName", ...args);
All script functions must be declared using the following signature:
function MyFunction(obj, ...args) {
// obj = reference to the object owning the script
}
The engine will always pass the object as the first parameter.
// Enemy script
function TakeDamage(obj, amount) {
obj.hp -= amount;
Log("Damage received: " + amount);
}
// Player script
function Attack(obj) {
CallFunction("Enemy", "TakeDamage", 25);
}
// Enemy script
function IsAlive(obj) {
return obj.hp > 0;
}
// Player script
function Update(obj) {
let alive = CallFunction("Enemy", "IsAlive");
if (!alive) {
Log("The enemy has been defeated");
}
}
Here CallFunction returns the enemyβs state so the player can make decisions.
CallFunction() is the only method to invoke internal or external functions