How to draw an array?

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

Hey I’m very new to GODOT so excuse me for my ignorance. I’m trying to figure out how to implement the following thing: I have an n dimensional array representing a map of land and water. I want to display this array as an image for debugging purposes without writing to disk. - for instance like previewing a depth buffer or something…

tldr:
Lets say I have a 3x3 array:

0,1,0
1,0,0
0,0,0

I want a visual representation of this array…

thanks.

By visual you mean something you can see on the game screen, during runtime?

Saitodepaula | 2019-12-05 13:43

:bust_in_silhouette: Reply From: Nikas

For example, so:

var x_max = 4
var y_max = 3
var matrix = createMatrix(x_max,y_max)
var x = 1
var y = 2
matrix[y][x]=1
printMatr(matrix)

This print:

[0, 0, 0, 0]
[0, 0, 0, 0]
[0, 1, 0, 0]

Where funcs is:

func printMatr(m):
  for x in range(0,len(m)):
    print(m[x])


func createMatrix(w,h):
  var matr=[]
  for y in range(h):
	matr.append([])
	for x in range(w):
		matr[y].append(0)
  return matr