Scripting: Iterating over TileMap layers?

I’m just getting started with Tiled’s scripting API, and I’m having a bit of difficulty figuring out how to access layers other than the current layer. TileMap.selectedLayers is close to what I’m looking for, but with all layers instead of the prerequisite of having to select the layers. Am I missing something or is this just something not implemented in the API?

TileMap.layerAt(index) is what you’re looking for. The index will be from 0 to TileMap.layerCount - 1.

Note, however, that if you want to iterate over layer Groups as well, you’ll need to iterate recursively, as Groups count as one top-level layer but include layers within them.

2 Likes

That’s exactly what I was looking for. Thanks!
(Also, not sure how I missed that. It’s right in the docs…)

1 Like