It’s not a bug, it’s the intended behavior. I tried to explain to you why it behaves that way, and that you’re comparing local tile IDs to global tile IDs, even though they are not the same thing.
Each tileset specifies the global ID of its first tile as the “firstgid
” property. As you can read in the documentation, you can use that number to determine which tileset a certain global tile ID is referring to, and then by subtracting the “firstgid
” value, you get the local tile ID of the tile in that tileset.
Of course, you can also set up a look table based on the referenced tilesets so that you can look up the tiles by their global ID directly. However, you will need to add the value of the “firstgid
” property to each tile ID before added the tile to the lookup table.