ID:171482
 
Hi...again...is there a way I can get the following code NOT to delete new versions of stuff?
proc
SaveObjects()
var/savefile/F = new ("objects.sav")
var/list/L = new
for(var/obj/O in world)
O.saved_x = O.x
O.saved_y = O.y
O.saved_z = O.z
L += O
F[""] << L

LoadObjects()
var/savefile/F = new ("objects.sav")
var/list/L = new
F[""] >> L
if(!L) return
for(var/obj/O in world) if(O.loc) del(O)
for(var/obj/O in L)
O.loc = locate(O.saved_x,O.saved_y,O.saved_z)


I know the reason they do delete is because of the first for in Loading but if I take that out, I get a new instance of an obj thats already on the map, but now I have 2 versions of it, and every reboot it makes another one!

I need a way so that new instances that werent saved before will appear, but old ones dont get dups of them forever.
Now, remember, when you save the object the to the savefile in that way, every part of the object is saved including the vars. That means that when you save an object, you could make an obj/var/issaved=0 and
o.issaved=1
when you save it.

After doing that, you could load the map(the second for() in LoadObjects()) first and THEN you can do:
for(var/obj/O in L) O.loc = locate(O.saved_x,O.saved_y,O.saved_z)
for(var/obj/O in world)
if(!O:issaved)
del(O)
else
O:issaved=0//So it works the next time.
In response to Wizkidd0123
The colon is not neccessary here.