How to cancel timer event?

I have used the timers extension to run some code after a certain time period using the code shown below.

timer.after(3000, function () {})

Is there a way to cancel this event / stop it from running after it has been called?

Note: I have tried wrapping the function in an if statement (e.g. execute this code only if this condition is met and game is in this state), however, when my game returns to the state where the event is meant to be triggered, there is a chance that this event will still run, so this method doesn’t seem to work in my case.

1 Like

Edit:

I’ve fixed the problem by forking the timer repo and editing the extensions typescript manually.

Creating 2 blocks - one to fetch the ID of the event and one to cancel the event using that ID.

yeah, in typescript you can use setTimeout directly which supports this but, as you noted, it’s not available in the blocks extension.

1 Like

Not sure if I’m supposed to but I did submit a pull request to the repo.

Not that my code was the best approach - but this does seem like a cool and useful tool
to have for game development.

1 Like