Tried to access a deleted layer

I wrote a script to create a layer with a particular name if it doesn’t already exist. This works, unless the layer was previously created and then deleted. Then, my code that checks to see if that layer already exists actually returns a layer that isn’t in the sprite’s list of layers (having been deleted). Obviously the check passes so I don’t create a new layer and then when I use the returned layer the script errors.

Any way to flush out deleted layers?

Hi @psychicteeth, how are you listing the layers of the sprite? For example,

for i = 1,#app.sprite.layers do
  print(app.sprite.layers[i].name)
end

doesn’t print deleted layers.

Ah I just meant it’s not displayed in the list of layers in the UI.
Honestly I think this may have just been a bug in my lua code. The code’s changed a lot since then and works okay now, so please disregard all this.