Array Question

Hi there,

Is there a way to make an array that is not a single list, but to have x,y coordinates?

At the moment, I can only find information to make an array variable contain a list ie. [1,2,54,2,etc]

I’m asking because I want to use the array to define an 11x11, 2 dimensional space that a character is walking through, while taking into account the walls of a maze so that the character cannot walk through them.

If I have an array like this, I can have the programming check the array ahead to a space I want the character to move, to see if it’s a wall. Perhaps I would have the value 1, in it, as opposed to a value they could walk into like 0.

Am I clear as mud? :slight_smile:

2 Likes

Hi @shawnjoh,

You can use a multi-dimensional array to define an 11x11 grid. You’d then be able to access the numerical value of each cell in the grid.

You can refer to this site for more information on creating multi-dimensional arrays in TypeScript:

https://www.tutorialspoint.com/typescript/typescript_multi_dimensional_arrays.htm

Hope this helps.

All the best,
Seb

2 Likes

Absolutely perfect, thank you @Seb !

2 Likes