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

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:

1 Like

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

This line:


inserts “StartingHightForMakingWorld” which MakeCode thinks is a number thus it thinks StartingHeights[] is a number[] here.

This line:


and this line:

is why MakeCode thinks StartingHightForMakingWorld is a number because “change _ by _” only works on numbers.

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

You’re still treating CurrentHightForMakingWorld as a number:

and then you’re assigning CurrentHightForMakingWorld to EndHightForMakingWorld:

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

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

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

I changed this. it stll has errors.

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

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 ???)

Here is the current version of the Sprite Art!

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

1 Like