This.app.fire() doesn't work

I am trying to create a project where you have to wind a music box (it’s a fnaf clone) and when the player right clicks on the music box, it tells the music box to wind. For this to work, I use this.app.fire(), but it never does what I want. It always gives me this error:


Then when the music box unwinds all the way, it is supposed to use this.app.fire() to “kill” the player, but it gives me his error:

I have searched for people who had the same error, but I could only find people using this.fire(). I tried using this.fire() and it gave me the same error, even with the “fixed” code.

Can someone help?

Project: https://playcanvas.com/editor/scene/1327488

Hi @PitchBlackNights,

The setInterval method is missing the “this” context, you can bind(this) to the function
Screenshot 2022-02-08 012852

also same goes for the raycastFirst function

1 Like

Oh… wow… I would have never thought that something this simple would fix all my problems. Thanks!

If you’re ever wondering why something isn’t working when it should, it’s probably some JS shenanigan. This binding thing is usually the culprit, just add .bind(this) to everything just in case and you’re good.