remove "tick" runtime event

  • 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));
    
  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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:

    runtime.addEventListener("tick", () => Tick(runtime));
    

    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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)