ID:157262
 
When trying to load an atom from a savefile with a non-existent type, you get an error. Let's say you have /obj/Weapon/knife, but the new path you're using after version X is /obj/weapon/knife. Everyone with an old knife saved in their inventory is going to produce an error when trying to load.

This seems to happen before the mob's contents can be evaluated to weed out these outdated type paths. Would the only way to remove these old objects be by manipulating the savefile as a text file (file2text and then ExportText before actually loading)?
That's one solution. The other is to keep the obsolete type around for compatibility reasons, and have it replace itself with a new object:

obj/Weapon
Read(var/savefile/F)
var/obj/weapon/w = new(loc)
w.Read(F)
del(src)


Note that this would be an incomplete solution, as it would only hold for the simple case. Objects storing references to one another complicates things, and the only general solution there would be text processing. It's not too difficult to generalize, though, but it may be rather slow, which is a damn good reason to mark your savefiles with a version number so you only need to perform the compatibility checks when a savefile needs to be updated. Anyway, the solution might look like this:

var/const/list/type_replacements = list(
"/obj/Weapon" = "/obj/weapon"
)

proc
update_savefile(var/savefile/F)
var/text = F.ExportText("/")
for(var/typename in type_replacements)
var/pos = findtextEx(text, typename)
while(pos)
text = copytext(text, 1, pos) + type_replacements[typename] + copytext(text, pos+length(typename))
var/pos = findtextEx(text, typename, pos)
F.ImportText("/",text)