How to get objects from layer by scripting API?

Here is my example.

let layer = map.layerAt(i);
if (layer.isObjectLayer) {
    for (let i = 0; j < layer.objectCount; i++) {
        let object = layer.objectAt(i);
    }
}

Sadly, it’s wrong: TypeError: Property ‘objectAt’ of object Tiled::EditableTileLayer(0x5ab2523e9e80) is not a function

1 Like

So, layer.objectAt doesn’t work, but layer.objects yes.
I don’t know why.

let layer = map.layerAt(i);
if (layer.isObjectLayer) {
    for (const o of layer.objects) {
        tiled.log(`obj: ${o.id}, ${o.text}`)
    }
}
1 Like

This says your layer is a Tile Layer. Did you actually have the layer.IsObjectLayer check in there when you ran the code?

Oh, I re-run it, layer.objectAt is ok now. Sorry for my mistake, maybe I’m forgot to save it before. Just ignore it.

let layer = map.layerAt(i);
if (layer.isObjectLayer) {
    for (let i = 0; j < layer.objectCount; i++) {
        let object = layer.objectAt(i);
    }
}

Maybe I forget to save the code. Sorry. just ignore it