# How to cancel timer event?

**URL:** https://forum.makecode.com/t/how-to-cancel-timer-event/33141
**Category:** Arcade
**Tags:** extension
**Created:** [January 15, 2025, 5:36pm UTC](https://forum.makecode.com/t/how-to-cancel-timer-event/33141 "2025-01-15T17:36:28Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![auto-koala](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/auto-koala/32/21019_2.png) [@auto-koala](https://forum.makecode.com/u/auto-koala)
#### Post date: [January 15, 2025, 5:36pm UTC](https://forum.makecode.com/t/how-to-cancel-timer-event/33141/1 "2025-01-15T17:36:28Z")

</div>

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

```auto
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.

---

<div class="post-metadata">

### Author: ![auto-koala](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/auto-koala/32/21019_2.png) [@auto-koala](https://forum.makecode.com/u/auto-koala)
#### Post date: [January 15, 2025, 5:59pm UTC](https://forum.makecode.com/t/how-to-cancel-timer-event/33141/2 "2025-01-15T17:59:32Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![richard](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/richard/32/5417_2.png) [@richard](https://forum.makecode.com/u/richard)
#### Post date: [January 15, 2025, 6:42pm UTC](https://forum.makecode.com/t/how-to-cancel-timer-event/33141/3 "2025-01-15T18:42:20Z")

</div>

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

---

<div class="post-metadata">

### Author: ![auto-koala](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/auto-koala/32/21019_2.png) [@auto-koala](https://forum.makecode.com/u/auto-koala)
#### Post date: [January 15, 2025, 7:02pm UTC](https://forum.makecode.com/t/how-to-cancel-timer-event/33141/4 "2025-01-15T19:02:17Z")

</div>

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.
