View Single Post
  #10  
Old 08-18-2017, 08:00 PM
BigNews BigNews is offline
Registered User
BigNews's Avatar
Join Date: Feb 2015
Posts: 3
BigNews has a spectacular aura aboutBigNews has a spectacular aura about
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."_" this.y;
  
temp.this.level.listenerCoords.index(temp.coord);

  if (
temp.== -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)

Last edited by BigNews; 08-18-2017 at 08:11 PM..
Reply With Quote