# Tile Layer with secondary tileset exports data with wrong indexes

**URL:** <https://discourse.mapeditor.org/t/tile-layer-with-secondary-tileset-exports-data-with-wrong-indexes/5892>\
**Category:** Questions\
**Created:** [November 12, 2022, 4:09pm UTC](https://discourse.mapeditor.org/t/tile-layer-with-secondary-tileset-exports-data-with-wrong-indexes/5892 "2022-11-12T16:09:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![EnJonas](https://avatars.discourse-cdn.com/v4/letter/e/f17d59/32.png) [@EnJonas](https://discourse.mapeditor.org/u/EnJonas)\
**Post date:** [November 12, 2022, 4:09pm UTC](https://discourse.mapeditor.org/t/tile-layer-with-secondary-tileset-exports-data-with-wrong-indexes/5892/1 "2022-11-12T16:09:02Z")

</div>

Hi! I’ve used Tiled for a little while, but I am new to this forum.

I am using Tiled for my own game engine, and I noticed some unexpected behavior when exporting a map file with multiple tilesets. The first tileset index data works correctly, with the first tile starting at 1. The second tileset though begins at index 9. I have a feeling the second tileset indexes are simply added on top of the existing tileset, but this really messes with the way I am reading and parsing the final file.

Is there a way to force Tiled to start all tilesets at index 1?

Hope my explanation is sufficient.

---

<div class="post-metadata">

**Author:** ![eishiya](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.mapeditor.org/eishiya/32/2534_2.png) [@eishiya](https://discourse.mapeditor.org/u/eishiya)\
**Post date:** [November 12, 2022, 4:42pm UTC](https://discourse.mapeditor.org/t/tile-layer-with-secondary-tileset-exports-data-with-wrong-indexes/5892/2 "2022-11-12T16:42:11Z")

</div>

Tiled assigns a different `firstgid` to each tileset, this is the way that tiles from different tilesets can be differentiated. If tile 0 from Tileset A was `1`, and tile 0 from Tileset B was `1`, how would you know which tileset the tile is from? However, if tiles 1-8 are Tileset A (firstgid = 1) and tiles 9+ are Tileset B (firstgid = 9), then you know which tileset each tile comes from.

The Tiled map file has the `firstgid`s for all the tilesets listed along with the tileset, you need to use that value instead of assuming `1`.

TMX and TMJ are built around global tile IDs, and you cannot change this. You can create your own custom formats via scripting, though - but keep in mind that you’ll need to come up with some way to distinguish tiles from different tilesets, and the `firstgid` approach is one of the simplest there is.

---

<div class="post-metadata">

**Author:** ![EnJonas](https://avatars.discourse-cdn.com/v4/letter/e/f17d59/32.png) [@EnJonas](https://discourse.mapeditor.org/u/EnJonas)\
**Post date:** [November 13, 2022, 6:10pm UTC](https://discourse.mapeditor.org/t/tile-layer-with-secondary-tileset-exports-data-with-wrong-indexes/5892/3 "2022-11-13T18:10:27Z")

</div>

That makes sense, I had decided to only use one tileset per layer for simplicity’s sake, but I might as well implement multiple tileset support now. Did not know about the firstgid parameter, thank you.
