Phaser 3, function doesn't exist/not defined

0

I have a npc class which has a method called chase that is referenced inside the update function. when chase is called it says its not a function or it’s not defined. I have another method being referenced in the same way that works.

image

chase method.

image

chase is called at npc_spr.chase(); this creates an error while above the bullet_spr.updateMe() works. updateMe is also a method.

what I expected to happen was for the method to be called like the one above. I have tried many different ways of rewriting it but everything results in the not defined or not a function error.

:wave:

Probably change to

chase() {
  this.scene.physics.moveToObject(this, player_spr, 100);

  this.anims.play('NPC', true);
}

Assuming that player_spr is a global variable or in scope somehow.

Thank you for the reply.

I might not have explained very well. There’s two groups one for bullets and one for npcs. Both bullets and npcs have their own class. when I call a method from the bullet class (updateMe) it works but when I call a method from the npc class in the same way I get the error - Uncaught TypeError: npc_spr.chase is not a function. The only difference between the groups is that the npc group has a createMultiple and a small bit of code to randomly place the npcs

Either the NPC class doesn’t have chase() or the NPC group doesn’t have NPCs in it, I would guess.

Maybe add some console logs or look at values in the debugger.

createMultiple() creates Sprites unless classType is set before that.