I tried it in many ways and it's still not removed
runtime.removeEventListener("tick",Tick);
runtime.removeEventListener("tick",() => Tick(runtime));
But why do you want to do this?
Have you tried deleting these lines of code?
runOnStartup(async runtime => { runtime.addEventListener("beforeprojectstart", () => OnBeforeProjectStart(runtime)); }); function OnBeforeProjectStart(runtime) { runtime.addEventListener("tick", () => Tick(runtime)); } function Tick(runtime) { }
Or these?
runtime.addEventListener("tick", () => Tick(runtime));
Develop games in your browser. Powerful, performant & highly capable.
I just tried it and it works for me.
You have to make sure you pass exactly the same function reference to both addEventListener and removeEventListener. If you do this:
addEventListener
removeEventListener
then you haven't saved the function reference anywhere, so it's impossible to remove it. Instead you have to save the function reference to a variable like this:
const tickFunc = () => Tick(runtime); runtime.addEventListener("tick", tickFunc); // later on... runtime.removeEventListener("tick", tickFunc);
That ensures you pass the same function reference to both methods. Note if you try to remove () => Tick(runtime) again, or just Tick, those are both different functions to the one you added the event with so it won't work.
() => Tick(runtime)
Tick