# Tileset Strange behaviour Bug or misunderstanding

**URL:** <https://phaser.discourse.group/t/tileset-strange-behaviour-bug-or-misunderstanding/14358>\
**Category:** Phaser 3\
**Created:** [May 26, 2024, 4:52pm UTC](https://phaser.discourse.group/t/tileset-strange-behaviour-bug-or-misunderstanding/14358 "2024-05-26T16:52:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![akumagamo](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/akumagamo/32/6031_2.png) [@akumagamo](https://phaser.discourse.group/u/akumagamo)\
**Post date:** [May 26, 2024, 4:52pm UTC](https://phaser.discourse.group/t/tileset-strange-behaviour-bug-or-misunderstanding/14358/1 "2024-05-26T16:52:29Z")

</div>

I just stumbled over [this issue](https://stackoverflow.com/q/78534357/1679286) on Stackoverflow and thought, if this is an bug/issue I should maybe open it, on the phaser github repo.

The issue seems to be, if I pass multiple tilesets to `createBlankLayer` and use `putTileAt` with a `gid` / Tile-Number that exceeds the max size of possible tiles in one of the tileset images, this generates an error _(of course with the `gid` within the combined total of all tilesets tile-count)_:

**TypeError: Cannot read properties of undefined (reading ‘2’)**

I create a code pen, with the SO-Code, so that it throws this Error _(in the console)_: [https://codepen.io/akumagamo/pen/ExzgMBP](https://codepen.io/akumagamo/pen/ExzgMBP)

So my question is, is this I Bug and should I post it on github, or did I misunderstand how this feature should be used. If the later, how could/should the feature be used?

Thanks in advance for the support.

---

<div class="post-metadata">

**Author:** ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)\
**Post date:** [May 27, 2024, 12:07am UTC](https://phaser.discourse.group/t/tileset-strange-behaviour-bug-or-misunderstanding/14358/2 "2024-05-27T00:07:16Z")

</div>

Pass `firstgid` in `addTilesetImage()` instead.

---

<div class="post-metadata">

**Author:** ![akumagamo](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/akumagamo/32/6031_2.png) [@akumagamo](https://phaser.discourse.group/u/akumagamo)\
**Post date:** [May 27, 2024, 4:26am UTC](https://phaser.discourse.group/t/tileset-strange-behaviour-bug-or-misunderstanding/14358/3 "2024-05-27T04:26:35Z")

</div>

Thank you, that worked like a charm. 👍

---

<div class="post-metadata">

**Author:** ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)\
**Post date:** [May 31, 2024, 2:36pm UTC](https://phaser.discourse.group/t/tileset-strange-behaviour-bug-or-misunderstanding/14358/4 "2024-05-31T14:36:57Z")

</div>

You can also set those manually if you rebuild the tileset index afterwards.

```js
tiles1.firstgid = 0;
tiles2.firstgid = tiles1.firstgid + tiles1.total;
tiles3.firstgid = tiles2.firstgid + tiles2.total;
tiles4.firstgid = tiles3.firstgid + tiles3.total;

map.tiles = Phaser.Tilemaps.Parsers.Tiled.BuildTilesetIndex(map);

```
