# Force screen update

**URL:** <https://forum.makecode.com/t/force-screen-update/4532>\
**Category:** Game Design\
**Created:** [November 20, 2020, 8:08pm UTC](https://forum.makecode.com/t/force-screen-update/4532 "2020-11-20T20:08:50Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![UnsignedArduino](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/unsignedarduino/32/592_2.png) [@UnsignedArduino](https://forum.makecode.com/u/UnsignedArduino)\
**Post date:** [November 20, 2020, 8:08pm UTC](https://forum.makecode.com/t/force-screen-update/4532/1 "2020-11-20T20:08:50Z")

</div>

Would it be possible to include a block that would force Arcade to redraw the screen? Or even a JavaScript command, like `game.update_screen()`? So we don’t have to include `pause(100)` whenever we want to update the screen, like during a resource-intensive function that’s displaying a progress bar. (For me, that’s calculating 20 different paths over a 64x12 tilemap using Joey’s A\* extension. It’s actually pretty slow when the tilemap is that big, which is understandable.) Or will even calling `pause (1)` update the screen?

---

<div class="post-metadata">

**Author:** ![charliegregg](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/charliegregg/32/2411_2.png) [@charliegregg](https://forum.makecode.com/u/charliegregg)\
**Post date:** [November 21, 2020, 4:12am UTC](https://forum.makecode.com/t/force-screen-update/4532/2 "2020-11-21T04:12:06Z")

</div>

When I used sprites and stuff I think pause(0) or pause(1) worked but that was a while ago. I could be wrong.

---

<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 22, 2020, 2:53pm UTC](https://forum.makecode.com/t/force-screen-update/4532/3 "2020-11-22T14:53:05Z")

</div>

Maybe you can explain what you are trying to achieve? I don’t quite understand why you would pause just to update the screen, since the screen IS being updated every few milliseconds. The amount of time between a ‘game update’ is not fixed, as that is dependent upon the hardware and sprites and events it has to process, but in each ‘update’ of the scene, the following occurs:

[Game Loop (makecode.com)](https://arcade.makecode.com/developer/game-loop)

---

<div class="post-metadata">

**Author:** ![UnsignedArduino](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/unsignedarduino/32/592_2.png) [@UnsignedArduino](https://forum.makecode.com/u/UnsignedArduino)\
**Post date:** [November 22, 2020, 6:03pm UTC](https://forum.makecode.com/t/force-screen-update/4532/4 "2020-11-22T18:03:14Z")

</div>

If you have a resource intensive function running that doesn’t have any delays in it, the screen won’t update unless I put in a delay. For example, I manually draw a progress bar to track it. If I don’t put in the delay, it goes from 0 to 100 after 20 seconds instantly. If I put in a delay, it goes smoothly from 0 to 100 after around 25 seconds.

---

<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 22, 2020, 11:17pm UTC](https://forum.makecode.com/t/force-screen-update/4532/5 "2020-11-22T23:17:50Z")

</div>

You could use a status bar like this.

> **[Health bar](https://arcade.makecode.com/56289-34933-62166-02384)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

I think the default value of the status bar is 100, and every 100 milliseconds I change the value by -1. This should mean that the game ends after approximately 10 seconds.

---

<div class="post-metadata">

**Author:** ![UnsignedArduino](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/unsignedarduino/32/592_2.png) [@UnsignedArduino](https://forum.makecode.com/u/UnsignedArduino)\
**Post date:** [November 22, 2020, 11:46pm UTC](https://forum.makecode.com/t/force-screen-update/4532/6 "2020-11-22T23:46:04Z")

</div>

The problem isn’t the status bar - my drawing routines aren’t being called (which is a `draw on z index` handler in Joey’s sprite utilities) during my resource intensive function, unless I put in a delay between each step of the function.

---

<div class="post-metadata">

**Author:** ![UnsignedArduino](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/unsignedarduino/32/592_2.png) [@UnsignedArduino](https://forum.makecode.com/u/UnsignedArduino)\
**Post date:** [November 22, 2020, 11:47pm UTC](https://forum.makecode.com/t/force-screen-update/4532/7 "2020-11-22T23:47:11Z")

</div>

And my status bar ain’t cosmetic. 🙂

---

<div class="post-metadata">

**Author:** ![charliegregg](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/charliegregg/32/2411_2.png) [@charliegregg](https://forum.makecode.com/u/charliegregg)\
**Post date:** [November 23, 2020, 4:35am UTC](https://forum.makecode.com/t/force-screen-update/4532/8 "2020-11-23T04:35:01Z")

</div>

Hmm. Why does it take an extra 5 secs

---

<div class="post-metadata">

**Author:** ![UnsignedArduino](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/unsignedarduino/32/592_2.png) [@UnsignedArduino](https://forum.makecode.com/u/UnsignedArduino)\
**Post date:** [November 23, 2020, 4:58am UTC](https://forum.makecode.com/t/force-screen-update/4532/9 "2020-11-23T04:58:28Z")

</div>

I’ve checked the time difference and it actually takes around 10 seconds with the delays and 7 seconds without the delays. (Moved the code around and benchmarked it) This is because I have 3000 ms delay split over 30 iterations. (100 ms per sprite) Arcade takes this time in between to update the screen.

---

<div class="post-metadata">

**Author:** ![charliegregg](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/charliegregg/32/2411_2.png) [@charliegregg](https://forum.makecode.com/u/charliegregg)\
**Post date:** [November 23, 2020, 10:18am UTC](https://forum.makecode.com/t/force-screen-update/4532/10 "2020-11-23T10:18:17Z")

</div>

I know there is an extension for running code in the background. Could that help here?

---

<div class="post-metadata">

**Author:** ![UnsignedArduino](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/unsignedarduino/32/592_2.png) [@UnsignedArduino](https://forum.makecode.com/u/UnsignedArduino)\
**Post date:** [November 23, 2020, 1:04pm UTC](https://forum.makecode.com/t/force-screen-update/4532/11 "2020-11-23T13:04:30Z")

</div>

It’s called `Timers`, and it shaved off 1 second. 🙂 (9 seconds left!!!)

---

<div class="post-metadata">

**Author:** ![UnsignedArduino](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/unsignedarduino/32/592_2.png) [@UnsignedArduino](https://forum.makecode.com/u/UnsignedArduino)\
**Post date:** [November 23, 2020, 1:07pm UTC](https://forum.makecode.com/t/force-screen-update/4532/12 "2020-11-23T13:07:53Z")

</div>

`pause(50)` and `pause(20)` also work but there is not difference under `50` ms. (7.5 seconds!)
