Tiled API scripting and firstgid

I am trying to find a tileset by gid, but there is no direct access and I figure I know why. What options do I have? At the moment I can search thru all the tilesets and test against each tile I suppose…

GIDs are a format-specific feature that doesn’t exist at runtime in Tiled and are only created when a file is written in a format that uses them, so it follows that firstgids also don’t exist at runtime. Where are you even getting a GID in a Tiled script? What exactly does your script need to do? Perhaps there’s a better approach that doesn’t involve GIDs.

While you can generate GIDs/firstgids in a Tiled script, there is no guarantee that these will match those written by the file formats or read in from the file the map was loaded from (indeed, it may even have been loaded from a format that doesn’t use GIDs), since those depend on the order of the tilesets in a given map, which may change between when your script runs and when the map file is written, and between different writes of the same map. You can choose to assume the tilesets will remain in the same order and generate the same GIDs though, perhaps in your workflow, that is a reasonable assumption.

Yeah, I figured it would be to uncertain of a value to relying on. I have another way to handle what I need. Thanks for the input.