area/savezone
atom/var
saved_x
saved_y
saved_z
world/Del()
var/i=1
var/savefile/F = new("data/areas.sav")
var/area/Area = locate(/area/savezone)
for(var/turf/T in Area.contents)
for(var/obj/O in T.contents)
if(istype(O,/mob/)) break
O.saved_x = O.x
O.saved_y = O.y
O.saved_z = O.z
F["[i]"] << O
i++
F["count"] << i
..()
world/New()
if(fexists("data/areas.sav"))
var/area/R = locate(/area/savezone)
for(var/turf/T in R)
for(var/obj/O in T)
del(O)
var/savefile/F = new("data/areas.sav")
var/count
F["count"] >> count
for(var/i=1, i < count, i--)
var/obj/O
F["[i]"] >> O
O.loc = locate(O.saved_x, O.saved_y, O.saved_z)
..()
It 'works' (as in no runtime or compile-time errors) BUT references are not preserved. When the map loads some of the objects(especially objects that run on strings of references [see note 1]) lose their references. I heard that when you save a reference the object being referenced is saved as well. The circle like action (that occurs VERY often) may be what is causing the problems.
Note 1: Objects such as wires that have 2 variables. Each one of those variables points to another wire which in turn points to another wire which in turn... There is a chance that these form a circle of references aka
Obj1.ref = Obj2, Obj2.ref = Obj3, Obj3.ref = Obj1.
What I do when I need saved objects to "link" back up with each other is have the references converted to tags during saving, and then locate(the tag) a moment after loading.