Why does this var come up as "Nil"

Godot Version

v4.2.1.stable.mono.official [b09f793f5]

Question

Its meant to be a function that can return info about the gridmap (map) but no matter what I do the var always comes up as Nil

func get_save_array():
	# Define the 3 arrays to fill
	var poses = Array()
	var ids = Array()
	var orientations = Array()

	# For every block in GridMap get its info and append it to the arrays
	for i in map.get_used_cells():
		poses.append(i)
		ids.append(map.get_cell_item(i))
		orientations.append(map.get_cell_item_orientation(i))
	
	# Create an array of the other arrays
	var griditems = Array()
	griditems.append(poses)
	griditems.append(ids)
	griditems.append(orientations)

Are the map a gridmap node? Did you reference the gridmap to the var map?

func _ready():
   map = $Gridmap // or another path

Yep! Did that. I tried to refrence it by both print(type_string(griditems)) and by using it as an array, any of which return a similar error: Error calling utility function "type_string()": Nil

Btw, the script is inside the gridmap

then try change map. to self.

None of the functions used to get cell info are defined in self.

self. is mean GridMap

since you write that the script is inside GridMap, you just need to write

for i in self.get_used_cells():

or

for i in get_used_cells():

Dont know what’s up with the error but I can access its contents using this (bad) source code: PasteBin

Also thats because I was extending Node rather Than GridMap

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.