The Initial Loop:
var/list/RepopMobs = list()
. . .
world
New()
. . .
spawn(20) for(var/mob/M in world) if(!M.client && /*misc checks to make sure it is the type of mob I want*/) RepopMobs.Add(M.type)
Then using this probably-functioning list, I attempt the repop in the way of creating a new mob of each path, matching it to an existing mob, then copying over the variables. Like so:
The Repop, in another proc:
. . .
for(var/mob/Monster/M in world)if(M)
if(M.NODELETEME)continue
for(var/X in RepopMobs)
if(M.type == X) // recall that X is a type path
var/mob/NEW = new X
for(var/S in M.vars)
if(S == "type" || S == "parent_type" || S == "client" || S == "key" || S == "verbs")
continue
NEW.vars[S] = M.vars[S]
break
del(M)
. . .
Problem description:
The issue with this is every time I run it, I get a new runtime error when this proc is called, on the line containing "NEW.vars[S] = M.vars[S]" -- always stating either "Cannot write to datum.(whatever)" or "Cannot write to atom.(whatever)". The first few times I simply added that variable to that little blacklist, though I fear I will have to do this infinitely at this rate because something is probably horribly wrong. This looks like the wrong way to go about this, but the lack of a mob-specific Repop() kills me. If I could simply do this, or a general equivalent, I would be happy:
for(var/mob/Monster/M in world)
M.Repop()
Destroying and creating things at runtime, especially on larger games can be very taxing (especially using del() which will have to check everything that exists for references to itself and wipe them, bigger games should never use del() unless Del() is doing something non-standard). It's usually always a better idea to recycle instead of rebuild.
A combination of a list that's smaller than 'world' and properly managing a recycling pool system will go a long way, and not just for mobs, objs too.