# Why Tilesets don't have ID?

**URL:** <https://discourse.mapeditor.org/t/why-tilesets-dont-have-id/4396>\
**Category:** Questions\
**Created:** [March 14, 2020, 5:20pm UTC](https://discourse.mapeditor.org/t/why-tilesets-dont-have-id/4396 "2020-03-14T17:20:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mihail\_Ilinov](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.mapeditor.org/mihail_ilinov/32/2643_2.png) [@Mihail\_Ilinov](https://discourse.mapeditor.org/u/Mihail_Ilinov)\
**Post date:** [March 14, 2020, 5:20pm UTC](https://discourse.mapeditor.org/t/why-tilesets-dont-have-id/4396/1 "2020-03-14T17:20:35Z")

</div>

I see that Maps and Tiles have “id” property.  
Is there a reason for the Tileset to don’t have such?

---

<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:** [March 14, 2020, 6:26pm UTC](https://discourse.mapeditor.org/t/why-tilesets-dont-have-id/4396/2 "2020-03-14T18:26:10Z")

</div>

Do you mean the gid/firstgid? If so, that’s because tilesets don’t know anything outside of themselves, so they only need to deal with the tiles within them. A tile’d ID is essentially its location within the tileset, and some properties may need to be tied to it, such as animations and collision data. The map assigns firstgids to each tileset it uses so that multiple tilesets can be used within the same map. The tileset itself has no need for any of this.

---

<div class="post-metadata">

**Author:** ![Mihail\_Ilinov](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.mapeditor.org/mihail_ilinov/32/2643_2.png) [@Mihail\_Ilinov](https://discourse.mapeditor.org/u/Mihail_Ilinov)\
**Post date:** [March 14, 2020, 7:02pm UTC](https://discourse.mapeditor.org/t/why-tilesets-dont-have-id/4396/3 "2020-03-14T19:02:30Z")

</div>

Ok so if I understand correctly.

Tilesets don’t have ID because they can be used on any map.  
And these IDs may get in a collision with other Tilesets.

When we add multiple Tilesets to a map (3 for example) each of the Tilesets receives a “ **firstgid** ” - which is the “ **gid** ” of the first tile in the tileset.

If so in the context of a map we could use these **firstgid** to differentiate between tilesets.

I’m making an export plugin and I needed a way to identify tileset by something and i didn’t want that something to be the “name” property.

After quick re-check:  
[https://doc.mapeditor.org/en/stable/reference/scripting/#id17](https://doc.mapeditor.org/en/stable/reference/scripting/#id17)  
It seems that this property is not exposed to the JS scripting API.  
@bjorn could it be added?

---

<div class="post-metadata">

**Author:** ![bjorn](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.mapeditor.org/bjorn/32/1599_2.png) [@bjorn](https://discourse.mapeditor.org/u/bjorn)\
**Post date:** [March 16, 2020, 8:30am UTC](https://discourse.mapeditor.org/t/why-tilesets-dont-have-id/4396/4 "2020-03-16T08:30:05Z")

</div>

> [@Mihail\_Ilinov](#):
>
> After quick re-check:  
> [https://doc.mapeditor.org/en/stable/reference/scripting/#id17](https://doc.mapeditor.org/en/stable/reference/scripting/#id17)  
> It seems that this property is not exposed to the JS scripting API.  
> @bjorn could it be added?

Well, we can’t really add a `firstgid` property to the tileset, because a tileset can be part of multiple maps, and for each map it may get a different `firstgid`.

In addition, there does not exist a `firstgid` property outside of the TMX and JSON map formats. These values get assigned while saving the map and are used while loading, but there would be no point in keeping them around.

If you just need to be able to refer to each tileset by a number, I would suggest you simply use their index in the map’s tilesets array. Would that work? Then, instead of this “global ID” system that the TMX and JSON map formats use, you could store each tile reference as a pair of “tileset index + tile id”.

---

<div class="post-metadata">

**Author:** ![Mihail\_Ilinov](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.mapeditor.org/mihail_ilinov/32/2643_2.png) [@Mihail\_Ilinov](https://discourse.mapeditor.org/u/Mihail_Ilinov)\
**Post date:** [March 16, 2020, 10:07am UTC](https://discourse.mapeditor.org/t/why-tilesets-dont-have-id/4396/5 "2020-03-16T10:07:53Z")

</div>

Yes that’s exactly what i did:

```
 for (let index = 0; index < this.map.tilesets.length; ++index) {
        const tileset = this.map.tilesets[index];
        const tilesetID = index + 1;
        ...
 }

```

offtopic: @bjorn I’m almost ready with the JS export plugin so I’ll send you a message for a quick code review when you have the time.

---

<div class="post-metadata">

**Author:** ![bjorn](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.mapeditor.org/bjorn/32/1599_2.png) [@bjorn](https://discourse.mapeditor.org/u/bjorn)\
**Post date:** [March 16, 2020, 10:43am UTC](https://discourse.mapeditor.org/t/why-tilesets-dont-have-id/4396/6 "2020-03-16T10:43:53Z")

</div>

> [@Mihail\_Ilinov](#):
>
> offtopic: @bjorn I’m almost ready with the JS export plugin so I’ll send you a message for a quick code review when you have the time.

Sure, I’m looking forward to see what you’re making!
