# Variable in Game Update Event not updating

**URL:** <https://forum.makecode.com/t/variable-in-game-update-event-not-updating/1773>\
**Category:** Help\
**Created:** [April 22, 2020, 9:52am UTC](https://forum.makecode.com/t/variable-in-game-update-event-not-updating/1773 "2020-04-22T09:52:39Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mickfuzz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/mickfuzz/32/419_2.png) [@mickfuzz](https://forum.makecode.com/u/mickfuzz)\
**Post date:** [April 22, 2020, 9:52am UTC](https://forum.makecode.com/t/variable-in-game-update-event-not-updating/1773/1 "2020-04-22T09:52:40Z")

</div>

Hi there,  
I’m trying to decrease the time between enemies spawning by putting a variable in the  
game update every event block.

 ![randomDoublingEnemies4](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/1X/c0cefb424e84582088a0ffdb35a0ca6ca8050477.png)

> **[Random Doubling Enemies Duck Run One Level](https://arcade.makecode.com/03946-33318-53917-66161)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

Looking at debug the value is going down, but no increase in numbers of projectiles spawning. Any ideas?

Thanks  
Mick

---

<div class="post-metadata">

**Author:** ![jwunderl](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/jwunderl/32/5308_2.png) [@jwunderl](https://forum.makecode.com/u/jwunderl)\
**Post date:** [April 22, 2020, 2:13pm UTC](https://forum.makecode.com/t/variable-in-game-update-event-not-updating/1773/2 "2020-04-22T14:13:10Z")

</div>

We talked about this once or twice in our livestreams; at 14:41 in [https://youtu.be/d1yP5oa8zTU](https://youtu.be/d1yP5oa8zTU) you can hear me fumbling through the explanation for this (it was my first time hosting the live stream so it was a bit extra awkward) - but the basic issue is just that the on game update is given an interval once, which is whatever spawnTime stores immediately after on start finishes. (I think we might change this in the future, so that it works in this sort of situation - it’s easy enough to fix, we just have to be sure its a thing we want to change and do it.).

The fix here is to use a forever loop, with a pause at the start or end that pauses for spawnTime. This value will be updated as it’s part of the body of the event, which is re run each time, and not the instantiation of the event, which is not.

---

<div class="post-metadata">

**Author:** ![mickfuzz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/mickfuzz/32/419_2.png) [@mickfuzz](https://forum.makecode.com/u/mickfuzz)\
**Post date:** [April 24, 2020, 4:24pm UTC](https://forum.makecode.com/t/variable-in-game-update-event-not-updating/1773/3 "2020-04-24T16:24:19Z")

</div>

Great! Thanks for the clear explanation 🙂  
That makes total sense.

---

<div class="post-metadata">

**Author:** ![mickfuzz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/mickfuzz/32/419_2.png) [@mickfuzz](https://forum.makecode.com/u/mickfuzz)\
**Post date:** [April 25, 2020, 2:07pm UTC](https://forum.makecode.com/t/variable-in-game-update-event-not-updating/1773/4 "2020-04-25T14:07:29Z")

</div>

Here’s the revised project in case anyone wants to see this in practice.

> **[Random Doubling Enemies Duck Run One Level](https://arcade.makecode.com/22317-53646-94074-80943)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

![randomDoublingEnemies5](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/1X/22c9bdc6cc1304b895bfac6389f0aefec0a2a321.png)

---

<div class="post-metadata">

**Author:** ![salieri](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/salieri/32/7275_2.png) [@salieri](https://forum.makecode.com/u/salieri)\
**Post date:** [November 1, 2020, 2:38am UTC](https://forum.makecode.com/t/variable-in-game-update-event-not-updating/1773/5 "2020-11-01T02:38:11Z")

</div>

Thank you so much for this work around. But man… why on earth is this even a bug?

---

<div class="post-metadata">

**Author:** ![cosmoscowboy](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/cosmoscowboy/32/1718_2.png) [@cosmoscowboy](https://forum.makecode.com/u/cosmoscowboy)\
**Post date:** [November 1, 2020, 10:48am UTC](https://forum.makecode.com/t/variable-in-game-update-event-not-updating/1773/6 "2020-11-01T10:48:29Z")

</div>

It is not a bug. As @jwunderl explains, the ‘game update interval’ event is registered with fixed interval.

---

<div class="post-metadata">

**Author:** ![ClarkEagling](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/clarkeagling/32/4044_2.png) [@ClarkEagling](https://forum.makecode.com/u/ClarkEagling)\
**Post date:** [April 29, 2021, 6:22pm UTC](https://forum.makecode.com/t/variable-in-game-update-event-not-updating/1773/7 "2021-04-29T18:22:11Z")

</div>

Huh, I just had this problem and came looking for an answer – glad I found it, but I could have sworn the pause block was pausing my whole game when I tried using it in the past.
