Convert to multi-dimensional arrays

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By givenmnisi6

How do I declare 2D arrays in Godot:

private int[,] prev;
private int[,] grid

:bust_in_silhouette: Reply From: Zylann

Is this a question about C# or GDScript? You tagged both…

There is an existing question covering GDScript: https://forum.godotengine.org/5122/how-do-i-create-a-2d-array?show=5122#q5122

For C#, it’s as you wrote it in your question, see Arrays - C# | Microsoft Learn

I am converting a C# script to Godot script so I am not sure how top change it, thats why.

givenmnisi6 | 2023-07-05 12:38

So you may replace it with one of the approaches described in the answer I linked. GDScript doesn’t have dedicated syntax for 2D arrays, but there are several other ways to make them. Use an array of arrays, a flat array, or a dictionary with Vector2i keys.

Zylann | 2023-07-05 13:59