+1 vote

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?

in Engine by (28 points)

1 Answer

+2 votes
Best answer

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 ^^;

by (7,922 points)
selected by

Jesus christ I am blind..
Thanks a lot!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.