TileMap's get_cell method returns wrong tile index?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By dogman
:warning: Old Version Published before Godot 3 was released.

Hello, I’ve got problem with this piece of code that’s supposed to find empty tiles by looping through the cells of a 32x32 tilemap:

const gridWidth = 32
const gridHeight = 32

var tilemap = get_parent().get_node("TileMap")

for x in range(gridWidth):
	for y in range(gridHeight):
		var tile_index = tilemap.get_cell(gridWidth, gridHeight)

The tile_index variable always ends up with the value of 1, even though I’ve got plenty of other type of tiles, also empty ones.

However if I print try printing tile indexes with constant values like this:


Then it prints the correct -1 value.

What could be the problem?

:bust_in_silhouette: Reply From: eons

You are getting always the same tile index with

var tile_index = tilemap.get_cell(gridWidth, gridHeight) #the const/limit values

It should be

var tile_index = tilemap.get_cell(x, y)

This kind of things happens to everybody ^^;

Jesus christ I am blind…
Thanks a lot!

dogman | 2017-02-22 22:37