ID:135096
 
I often find myself and other people doing:

var/obj/explosion1/O = new(src)
var/obj/explosion2/O2 = new(src)
var/obj/explosion3/O3 = new(src)
sleep(50)
del(O)
del(O2)
del(O3)


Is there a way or could there be a way to make simple roots like:

root/explosionroot //have a fixed root thing(like we have objs) and then be able to define a certain root(like we can do obj/myobj)
var/obj/explosion1/O = new(src)
var/obj/explosion2/O2 = new(src)
var/obj/explosion3/O3 = new(src)
sleep(50)
del(root/explosionroot)


Which should delete all atoms inside explosionroot.
Try something like:

for(var/obj/Explosions/O in typesof(/obj/Explosions))// /obj/Explosions/Exposions1; /obj/Explosions/Exposion2; /obj/Explosions/Explosions3
O=new(src)

sleep(50)

for(var/obj/Explosions/O in src)del O


I'm really not sure if this would work, but something along the lines would.
What it will do is delete all of explosionroot's references to those atoms. If those atoms aren't referenced anywhere else, then the garbage collector will delete them too. But if they are referenced in another variable somewhere, they'll continue to exist.

Why not loop through a list and delete them that way instead?
In response to Jon88
Or you could give them a nice little tag, and check if that tag is equal to the tag you gave them.
In the case of explosionroot1, 2, 3, etc., I've found there's seldom a good reason to organize your objects that way. There's almost undoubtedly a much better way to handle those, and I don't just mean giving them a common root type (which yes, they should have)--I mean giving them all the same type.

Question: What's so different about explosions 1, 2, and 3, and does it really require a separate type for each one?

Lummox JR