# Tilemap wont be set to a variable even tho the variable is a tilemap

**URL:** <https://forum.makecode.com/t/tilemap-wont-be-set-to-a-variable-even-tho-the-variable-is-a-tilemap/38199>\
**Category:** Help\
**Tags:** game\
**Created:** [July 20, 2025, 6:19pm UTC](https://forum.makecode.com/t/tilemap-wont-be-set-to-a-variable-even-tho-the-variable-is-a-tilemap/38199 "2025-07-20T18:19:12Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![spacemakecodenugget](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/spacemakecodenugget/32/21009_2.png) [@spacemakecodenugget](https://forum.makecode.com/u/spacemakecodenugget)\
**Post date:** [July 20, 2025, 6:19pm UTC](https://forum.makecode.com/t/tilemap-wont-be-set-to-a-variable-even-tho-the-variable-is-a-tilemap/38199/1 "2025-07-20T18:19:12Z")

</div>

i am very confused about this… the title is self explanitory…

 ![makecode, how could you let this happen](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/3X/3/3/337b13e39c8aa15be8c10784577aa3bf2a86ff6f.png)

heres a link to the game: [https://arcade.makecode.com/S63482-92845-76657-74915](https://arcade.makecode.com/S63482-92845-76657-74915)

---

<div class="post-metadata">

**Author:** ![Stickman4269](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/stickman4269/32/23582_2.png) [@Stickman4269](https://forum.makecode.com/u/Stickman4269)\
**Post date:** [July 20, 2025, 11:31pm UTC](https://forum.makecode.com/t/tilemap-wont-be-set-to-a-variable-even-tho-the-variable-is-a-tilemap/38199/2 "2025-07-20T23:31:45Z")

</div>

Probably because you’re using an outdated version of tile-util

---

<div class="post-metadata">

**Author:** ![BotWarrior](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/botwarrior/32/25328_2.png) [@BotWarrior](https://forum.makecode.com/u/BotWarrior)\
**Post date:** [July 21, 2025, 2:59am UTC](https://forum.makecode.com/t/tilemap-wont-be-set-to-a-variable-even-tho-the-variable-is-a-tilemap/38199/3 "2025-07-21T02:59:07Z")

</div>

Ummm… I see what you are trying to do. I don’t know how to do it without saving the positions of all tiles.  
Can I offer a few suggestions after looking at the code? I don’t think you need to set the tile map on a forever loop. I think you need all of this code to run once, otherwise you have an infinite amount of Menu BG and a lot of lag. When you open menu, do all the code you want to do, the toggle states when it is pressed again. If you have any sprites on the tile map, I would suggest getting arrays like this-

 ![Screenshot 2025-07-21 at 08.04.47](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/3X/5/b/5b5822cfb76a890bf357fc847d43437f0e05e1e7.png)  
only if you need it of course. Just wanted to help

---

<div class="post-metadata">

**Author:** ![Makecoder](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/makecoder/32/23787_2.png) [@Makecoder](https://forum.makecode.com/u/Makecoder)\
**Post date:** [July 21, 2025, 2:59am UTC](https://forum.makecode.com/t/tilemap-wont-be-set-to-a-variable-even-tho-the-variable-is-a-tilemap/38199/4 "2025-07-21T02:59:43Z")

</div>

the current tilemap also has not been set so it might not work

---

<div class="post-metadata">

**Author:** ![BotWarrior](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/botwarrior/32/25328_2.png) [@BotWarrior](https://forum.makecode.com/u/BotWarrior)\
**Post date:** [July 21, 2025, 4:28pm UTC](https://forum.makecode.com/t/tilemap-wont-be-set-to-a-variable-even-tho-the-variable-is-a-tilemap/38199/5 "2025-07-21T16:28:39Z")

</div>

It gets set at some point in the code. On start I think.

---

<div class="post-metadata">

**Author:** ![swirlix](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/swirlix/32/35624_2.png) [@swirlix](https://forum.makecode.com/u/swirlix)\
**Post date:** [July 21, 2025, 9:42pm UTC](https://forum.makecode.com/t/tilemap-wont-be-set-to-a-variable-even-tho-the-variable-is-a-tilemap/38199/6 "2025-07-21T21:42:08Z")

</div>

because the tilemap variable only gets defined if the menu is open, if the game starts and the menu isn’t open, the game trys to set the tilemap to a variable that has not been defined. I bet someone else can explain this in better words than me but this is my best shot at explaining it.
