ID:1544065
 
(See the best response by MisterPerson.)
I want to revert all vars on a mob to their initial value.

I tried looping thru their vars list and doing var_name=initial(var_name) on each one.

This works fine until it reaches a read-only var, then it gives an error that I can't change read-only vars, then the loop stops.

How can I skip read-only vars? I don't know of any way to differentiate between vars and read only vars.

Thanks
Best response
Look up the issaved() proc in the DM ref
Thanks. It works. Except that it skips tmp vars. Is there a way to recognize those? They need to be reset as well
Well..

Creating a copy of the vars list and removing known read-onlys works:

mob/verb/Reset_Variables()
var/list/variables=vars.Copy(1,vars.len+1)
var/list/disallow=list("type","gender","vars","parent_type","mob","ckey","key","client","screen_loc","group","locs","verbs")
variables-=disallow
for(var/v in variables)
set background=1
vars[v]=initial(v)


However, if you are wanting to do something like this to reset players, there is a much simpler way.

mob/verb/Reset_Variables_2()
client.mob=new type
del(src)//If there are no references to the mob, setting loc to null will allow the trash collector to pick it up.