Inter-component communication

Just wondering if there are any patterns that others have found that scale well for inter-component communication. In particularly to avoid coupling.

Do you use primarily events? I can’t see a simple way to do injection in this game engine (using the online tools) - but using a pub/sub pattern seems to work fine, but could be a bit hard to debug with a larger project.

Any thoughts?

Cheers.

I use events. Each script fires events on the app object and anyone interested simply listens for those events again on the app object. Makes things pretty simple.

It makes it simple - but I read it might kill the performance… !?

Anybody knows it is better to search for the ‘script to call’-holding entity at the initialize function once and
the directly set parameters via .script.myvariable or call functions via .script.myfunction() from other scripts?

I use events for the most part too to keep things as decoupled as possible.

For areas where it makes sense, I use an event to ‘register’/‘deregister’ a script or entity to a controller which holds it as a reference in a list and does processing on that list.

This still keeps things quite clean in code while having direct access to the object needed.

What do you do with things like static methods? Say for instance a math library?

I either extend an existing library (like the PlayCanvas engine), or create my own object/namespace.

eg.

var yaustar = {};
yaustar.someStaticFunction = function() {
  console.log("hello world");
};

I’ve done a project which heavily uses events if you want to take a look: https://playcanvas.com/project/475452/overview/isometric-base-builder