Option to export tile data with 0-based indexes?

Is there some option to export tile layer data using a base of 0, instead of 1?
I.e. In the exported data for a map, currently the first tile is referenced by an ID of 1:
“layers”:[
{
“data”:[1, 1, 1, 5, 7, 1, 1, 1, 1, 1, 1, 5, 7, 1, 2, 3, 1, 1, 1, 5, 7, 1, 5, 6, 1, 1, 1, 5, 7, 1, 5, 6, 1, 1, 2, 11, 7, 1, 5, 6, 1, 1, 5, 6, 7, 1, 8, 9, 1, 1, 5, 6, 7, 1, 1, 1],
}

Working from most non-Lua languages, the first entry in an array/collection is 0, not 1, so I’ve got to fixup all these IDs when indexing into my texture atlases and other things.

Actually this index also starts at 0, but 0 means “no tile” / “empty cell”. So if you’re going to subtract 1, you need to check for 0 before otherwise you’re going to use an invalid index.

There is no option for disabling support for empty cells.

Thanks for the explanation.
I still think it is a little confusing, especially since if I select a tile in Tiled, under the properties window for that tile, the ID field is 0-based, and doesn’t match up with the exported data.
tile-properties

Right, but that ID is local to the tileset. It’s an index into the array of tiles in the tileset image, where there is no “empty cell” and 0 is simply the first tile.

The tile IDs saved in the TMX and JSON formats not only start at 1 because 0 is the empty cell, but they might also be shifted by larger amounts in case there are multiple tilesets used by the map. These are global IDs. But global IDs are not shown anywhere in Tiled because they are specific to the way the map is stored.

today it took my quite some time that the layers.data numbers array isn’t linked to the id’s in the tiles array but rather to the index of said array, which confused me a lot.
Is there a setting to make sure that these id’s start at 1 instead of 0?

No. The global IDs don’t really exist in Tiled, they are only a mechanism used by the TMX and JSON formats to allow a map to use tiles from multiple tilesets.

Hi Bjorn,

thank you for your quick reply!
After using multiple layers, it dawned that the firstgid of every tilelayer is used in combination with the individual tile id to get a global id which is used in the layers.data array.
This is why the first id starts at 1, because the firstgid starts at 1, to account for empty tiles I guess (see attached picture for future references)
image

Yes, except I’m sure you meant to say multiple tilesets and not multiple layers. :slight_smile:

Indeed, global ID 0 is used for empty cells so the first tile in the first tileset always gets global ID 1.

In addition, if you’re going to rotate or flip your tiles, note that certain bits in the global ID are used to store this information.