# Can custom variable declaration somehow be made possible?

**URL:** <https://forum.makecode.com/t/can-custom-variable-declaration-somehow-be-made-possible/9356>\
**Category:** Arcade\
**Created:** [July 23, 2021, 5:00pm UTC](https://forum.makecode.com/t/can-custom-variable-declaration-somehow-be-made-possible/9356 "2021-07-23T17:00:29Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sarge](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/sarge/32/19590_2.png) [@Sarge](https://forum.makecode.com/u/Sarge)\
**Post date:** [July 23, 2021, 5:00pm UTC](https://forum.makecode.com/t/can-custom-variable-declaration-somehow-be-made-possible/9356/1 "2021-07-23T17:00:29Z")

</div>

Can somebody make an extrention or integrate this function in MakeCode?

 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/7/781f0c0e41caa701aa076482d8c2f248a40bd95d.png)

This way it is possible to make multiple variables mid-game and allow finally displaying an unlimited number of saved settings (settings already can be done this way, so why not functions?)

---

<div class="post-metadata">

**Author:** ![Sarge](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/sarge/32/19590_2.png) [@Sarge](https://forum.makecode.com/u/Sarge)\
**Post date:** [July 23, 2021, 6:41pm UTC](https://forum.makecode.com/t/can-custom-variable-declaration-somehow-be-made-possible/9356/3 "2021-07-23T18:41:14Z")

</div>

Hmm… Not quite what I asked for

---

<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:** [July 23, 2021, 6:41pm UTC](https://forum.makecode.com/t/can-custom-variable-declaration-somehow-be-made-possible/9356/4 "2021-07-23T18:41:59Z")

</div>

What you’re describing here effectively comes down to either an array or an object ([https://github.com/microsoft/arcade-block-objects](https://github.com/microsoft/arcade-block-objects)). The variables map to ‘normal’ javascript variables, which are all defined at declaration – it is uncommon to have dynamic variable names in programming languages as arrays / objects / maps cover that use case more accurately.

The case you mentioned (set `variable0`, set `variable1`, set `variable2`) is an example of when you would use an array – you create one and then index into it to grab values.

For arbitrary / non integer values, you would use objects to store groups of values - you keep around one variable and store things on top of that. (It’s possibly worth noting this is significantly slower, in particular on hardware, than using arrays and normal variables - something on the order of like 10-100 times longer to access the variable).

---

<div class="post-metadata">

**Author:** ![Sarge](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/sarge/32/19590_2.png) [@Sarge](https://forum.makecode.com/u/Sarge)\
**Post date:** [July 23, 2021, 7:18pm UTC](https://forum.makecode.com/t/can-custom-variable-declaration-somehow-be-made-possible/9356/5 "2021-07-23T19:18:46Z")

</div>

Yeah, but what if I need to show many text sprites at once? Then this happens:

 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/c/c2daa33c644c32bcf29fa1043fbbef96a259fdd2.png)  
Sure I can make a temporary variable that will store an array value and then repeat that but increase the index that it is collecting by one. However when I need to destroy said sprites it will only work once. That is kind of a bummer. Any way to avoid this?

---

<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:** [July 23, 2021, 7:54pm UTC](https://forum.makecode.com/t/can-custom-variable-declaration-somehow-be-made-possible/9356/6 "2021-07-23T19:54:20Z")

</div>

You can make an array of text sprites instead 🙂

 ![arcade-screenshot (2)](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/8/8b8728e8ffc050260262e5880f5d44ac1cf4267e.png)

also, instead of the repeat block, there are two other loop blocks that will more easily handle these; this one will do something once for each value in list:

![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/3/3fa26376880dc5a7e93445cd1f6cbb0d7702af29.png)

as will this, except this gives you an index as well (like you were doing manually with ‘selector’)

![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/3/39af7aad010b7def0d1d6d96662a6ba3a12030bd.png)

---

<div class="post-metadata">

**Author:** ![Sarge](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/sarge/32/19590_2.png) [@Sarge](https://forum.makecode.com/u/Sarge)\
**Post date:** [July 23, 2021, 9:45pm UTC](https://forum.makecode.com/t/can-custom-variable-declaration-somehow-be-made-possible/9356/7 "2021-07-23T21:45:53Z")

</div>

Thanks!
