# Problem with an array in an array (2d array)

**URL:** <https://forum.makecode.com/t/problem-with-an-array-in-an-array-2d-array/5327>\
**Category:** Help\
**Created:** [January 3, 2021, 6:38pm UTC](https://forum.makecode.com/t/problem-with-an-array-in-an-array-2d-array/5327 "2021-01-03T18:38:52Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![GameGod](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/gamegod/32/2756_2.png) [@GameGod](https://forum.makecode.com/u/GameGod)\
**Post date:** [January 3, 2021, 6:38pm UTC](https://forum.makecode.com/t/problem-with-an-array-in-an-array-2d-array/5327/1 "2021-01-03T18:38:52Z")

</div>

> **[otherworldly](https://arcade.makecode.com/90359-50739-35698-96852)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

There is an error in the code - how can I solve it?

It is saying something about one of my blocks. This block is an array in an array. It is meant to make a two-dimensional array. How can I fix the error? Is there an easier way to make a two-dimensional array?

Drawing to explain what I want:

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

---

<div class="post-metadata">

**Author:** ![darzu](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/darzu/32/1882_2.png) [@darzu](https://forum.makecode.com/u/darzu)\
**Post date:** [January 3, 2021, 6:52pm UTC](https://forum.makecode.com/t/problem-with-an-array-in-an-array-2d-array/5327/2 "2021-01-03T18:52:01Z")

</div>

“StartingHeights[]” variable is being used as both a number[][] and number[] so the MakeCode compiler is getting confused.

This line:

 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/2/2c478990ee875347e9ad846b716fa854b3e88d79.png)  
inserts “StartingHightForMakingWorld” which MakeCode thinks is a number thus it thinks StartingHeights[] is a number[] here.

This line:

 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/f/ff332696aaa8e332c1b63a92117d15e73e62d111.png)  
and this line:  
 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/8/84b99e97714e7eb4f948ddc49ff4deb94a0aa7df.png)  
is why MakeCode thinks StartingHightForMakingWorld is a number because “change \_ by \_” only works on numbers.

---

<div class="post-metadata">

**Author:** ![GameGod](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/gamegod/32/2756_2.png) [@GameGod](https://forum.makecode.com/u/GameGod)\
**Post date:** [January 3, 2021, 7:05pm UTC](https://forum.makecode.com/t/problem-with-an-array-in-an-array-2d-array/5327/3 "2021-01-03T19:05:39Z")

</div>

I think I’ve changed some things, but why is it still showing the error?

> **[otherworldly](https://arcade.makecode.com/12354-16214-90106-65809)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

---

<div class="post-metadata">

**Author:** ![darzu](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/darzu/32/1882_2.png) [@darzu](https://forum.makecode.com/u/darzu)\
**Post date:** [January 3, 2021, 7:09pm UTC](https://forum.makecode.com/t/problem-with-an-array-in-an-array-2d-array/5327/4 "2021-01-03T19:09:36Z")

</div>

You’re still treating CurrentHightForMakingWorld as a number:

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

and then you’re assigning CurrentHightForMakingWorld to EndHightForMakingWorld:

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

but also you’re expecting EndHightForMakingWorld to be a number[]:

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

---

<div class="post-metadata">

**Author:** ![GameGod](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/gamegod/32/2756_2.png) [@GameGod](https://forum.makecode.com/u/GameGod)\
**Post date:** [January 3, 2021, 7:20pm UTC](https://forum.makecode.com/t/problem-with-an-array-in-an-array-2d-array/5327/5 "2021-01-03T19:20:38Z")

</div>

Um, I’m sorry. I still am having trouble.

CurrentHightForMakingWorld is supposed to be a number. So is EndHightForMakingWorld.

> [@darzu](#):
>
> but also you’re expecting EndHightForMakingWorld to be a number:
> 
> ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/9/990274feba7d9152c6482ff95e0bf2d60e1fc227.png)

I changed this. it stll has errors.

> **[otherworldly](https://arcade.makecode.com/95418-75291-51504-98102)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

---

<div class="post-metadata">

**Author:** ![darzu](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/darzu/32/1882_2.png) [@darzu](https://forum.makecode.com/u/darzu)\
**Post date:** [January 3, 2021, 7:24pm UTC](https://forum.makecode.com/t/problem-with-an-array-in-an-array-2d-array/5327/6 "2021-01-03T19:24:26Z")

</div>

Good to know “StartingHightForMakingWorld” should be “number”. Therefore this is a problem:

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

because EndingHeights is number[][] (two dimensional like you said), when you do “get value at” from a number[][] you get a number[] in return which it is then trying to assign to StartingHightForMakingWorld.

(\_ get value at \_) “peels” one layer of an array’s type. So number[][] becomes number[], number[] becomes number, etc.

If you want to get a single number, you have to do ((EndingHeights[] get value at (CurrentMapX)) get value at ???)

---

<div class="post-metadata">

**Author:** ![DahbixLP](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/dahbixlp/32/4760_2.png) [@DahbixLP](https://forum.makecode.com/u/DahbixLP)\
**Post date:** [January 3, 2021, 7:34pm UTC](https://forum.makecode.com/t/problem-with-an-array-in-an-array-2d-array/5327/7 "2021-01-03T19:34:27Z")

</div>

Here is the current version of the Sprite Art!

> **[Otherworldly Sprite Art](https://arcade.makecode.com/16610-25760-60354-24532)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

---

<div class="post-metadata">

**Author:** ![GameGod](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/gamegod/32/2756_2.png) [@GameGod](https://forum.makecode.com/u/GameGod)\
**Post date:** [January 3, 2021, 9:59pm UTC](https://forum.makecode.com/t/problem-with-an-array-in-an-array-2d-array/5327/8 "2021-01-03T21:59:23Z")

</div>

Thanks! All my arrays were number[]. Then, I had to change them to number[][]. I didn’t know I missed that one!
