2d array/structure

Im very much a newby,

If i wanted to store say a virtual map or cells of a pacman maze, 32 by 32 grid, and access it by x, y. coordinates how would i do this?

Ect, ect

There are at least 3 ways to achieve this :

  1. Us an array of arrays. The first array is for the rows, the second array is for the the columns within that row :

  1. Use an array of strings, with each string representing the cells in a row. Slight change in variable definition and getting the cell value :

  1. Use a string that holds the complete grid - it’'ll be 1024 characters long (32x32) :

Pick whichever one you feel works best for you. Just remember that with these examples it’s accessed Y, X (and not the normal co-ordinate system x, y)

1 Like

Thanks that’s a big help!

On the last example, would i enter the maze details in one long string or enter one line of 32 then press enter and so on?

(Note that you can use the more convenient For each child variable event instead of a repeat event :wink:)

1 Like

One long string for the way it is in the screen snip.

If you want to split it into a more readable structure and do 32 chars and then press return, then I suspect GDevelop treats the return character as another char and you’ll have to multiply the row_number by 33.

Yes, if they are looping through the whole array. However, I also wanted to show the OP how to access any cell in the array, and thought two loop events would kill two birds with one stone, so to speak.

Thanks I have it working nicely, it shows the values of cells:
Centre, Left, Right, Up and Down, I want this info for my movement data and collision data, now the question is how can I turn this into a function just by passing the variables row_number and Column_number and getting back the data from cell_valueL, ect ect for all the directions?

hi, can anyone help with this, I have tried and tried to solve it but I can not figure out if its possible.

I would like to change the below into a function that I can repeatedly call.

I need to pass the two variables row_number and column_number and in return get the values of cell_valueL, R, U and D, will these variables have the values when the function finishes and I only have to pass the input variables?


I have now managed to get this working, was easy really and learned alot

Another odd question, how would i write a value at a certain index address

@djsedaw :


1 Like

thanks looks easy now-cheers