πŸ“ž Communication Between Scripts

πŸ”’ Isolated Environment

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:

πŸ’‘ Main Rule:
Do NOT call functions by typing MyFunction().
Always use CallFunction().

🎯 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);

🧩 Important

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.

βœ… Simple Example

// Enemy script
function TakeDamage(obj, amount) {
  obj.hp -= amount;
  Log("Damage received: " + amount);
}

// Player script
function Attack(obj) {
  CallFunction("Enemy", "TakeDamage", 25);
}

🎯 Example With Return Value

// 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.

πŸ“Œ Summary

βœ” Each object has a single isolated script
βœ” Scripts cannot call each other's functions directly
βœ” CallFunction() is the only method to invoke internal or external functions
βœ” It supports passing parameters and receiving return values