ID:1287264
 
(See the best response by FIREking.)
Code:
                        for(var/obj/spells/poison/the_spell in src.overlays)
src.overlays -= the_spell
for(var/obj/spells/boltboom/the_spell in src.overlays)
src.overlays -= the_spell


Problem description:

So.. I cannot do somethng like this?
Best response
Unfortunately, overlays list is not like a normal list. In order to be very fast, it is "unmanaged". What I mean by that is, you need a reference to each overlay in order to remove it... or you should keep your own list of overlays so that you can rebuild them when you need to make changes.

atom/var/list/managed_overlays = list()
atom/proc/clear_overlays()
src.overlays.Cut()
atom/proc/build_overlays()
for(var/v in managed_overlays)
src.overlays += v
atom/proc/remove_overlay(x)
managed_overlays -= x
atom/proc/add_overlay(x)
managed_overlays += x


So if you put a type path in the managed_overlays list, you'll be able to check that path for its path later on... like this

src.clear_overlays()
for(var/obj/spells/poison/the_spell in src.managed_overlays)
src.remove_overlay(the_spell)
src.build_overlays()


The reference says:
The individual items in the list may not be directly accessed, since they are stored in a special internal format. However, the list operators +=, -=, and the procedures Add, Remove, and Cut work normally.
Actually, a lot of the reason that the overlays list is different is because internally, BYOND keeps track of "appearances" by an internal ID handle. This keeps the engine from having to send too much unique data across the network.

Basically, your best bet is to set up a builder like Fireking has set up for you, and tie it to an internal list you've made yourself that allows you to interact with objects like you would expect.
In response to FIREking
To be on the safe side, checking the length of managed_overlays after you've removed it would be a tad better, as of right now you have no way of properly managing managed_overlays to prevent redundancies.

atom/proc/remove_overlay(x)
if(managed_overlays)
managed_overlays -= x
if(!managed_overlays.len)
managed_overlays = null
In response to Magnum2k
And adding_overlay, so you don't have to worry about if the list exists or not

atom/proc/add_overlay(x)
if(!managed_overlays) managed_overlays = list()
managed_overlays += x


There's also a lot of other things you could do! Like making the overlays automatically regenerate when you remove an overlay.

atom/proc/remove_overlay(x)
if(!managed_overlays) return //we don't have any overlays
var/tmp/len = managed_overlays.len //remember our list size
managed_overlays -= x //try to remove an item
if(managed_overlays.len != len) //only rebuild if our list size changed
clear_overlays()
build_overlays()