You'll probably want to do something like this:
Class A:
PHP Code:
//#CLIENTSIDE
function onCreated()
if (this.level.listeners.index(this.id) == -1)
this.level.listeners.add(this.id);
public function baz()
this.chat = "debug";
Class B:
PHP Code:
//#CLIENTSIDE
function onActionAHPhit() {
for (temp.id : this.level.listeners) {
findnpcbyid(temp.id).baz();
}
}
Because when the level is updated, it still retains any variables stored on the level object beforehand, which can cause array values to contain non-existent objects.
--------
Alternatively if you want to store the objects and be safe between level updates you could do something like:
Class A:
PHP Code:
//#CLIENTSIDE
function onCreated() {
temp.coord = this.x @ "_" @ this.y;
temp.i = this.level.listenerCoords.index(temp.coord);
if (temp.i == -1) {
this.level.listenerCoords.add(temp.coord);
this.level.listeners.add(this);
}
else
this.level.listeners[temp.i] = this;
}
Class B:
PHP Code:
//#CLIENTSIDE
function onActionAHPhit() {
for (temp.listener : this.level.listeners) {
temp.listener.baz();
}
}
(which assumes NPC coordinates are always unique)