CallFunction is an engine utility that allows you to
execute a specific function inside the script attached to an object.
This method is required because, due to the engineβs script isolation system,
functions defined inside scripts are not globally accessible and cannot be called directly
from other objects.
By design, each object executes its script inside a protected environment,
preventing other objects from directly accessing internal functions or altering behavior without control.
CallFunction acts as the only authorized bridge that safely and consistently
allows objects to invoke methods from one another.
CallFunction(target, method, ...args);
function Heal(obj, amount) {
obj.hp = (obj.hp ?? 100) + amount;
}
Call:
CallFunction(obj, "Heal", 25);
function IsAlive(obj) {
return obj.hp > 0;
}
let alive = CallFunction(obj, "IsAlive");
if (alive) {
console.log("The player is still alive");
}
undefined will stop the search.
| Feature | sendMessage | CallFunction |
|---|---|---|
| Scope | Calls the method in all scripts | Stops at the first valid method |
| Parameters | Supports parameters | Supports parameters and return values |
| Return Value | No return | Returns the first non-undefined value |