ID:149288
 
Alright, I have a game.

Duh.

Ok, so I have the fact that I have a game established, established. Now, we move on to the problem, as this is the Code Problems forum, and we should pos... err, moving right along...

Well, the game is known as
Survival
Can you make it? (or not make it, as Garthor would say)
Currently players are able to construct houses, start primitive villages, harvest, farm, craft, hunt, and plenty of other things. I have managed to get houses to save, but now my project is objects. How can I get my objects, on the map, to save to a file, then load at run-time (more specifically bootup)? I imagine it can't be much more than a savefile definition, and a for loop, but given my knowledge (lack thereof) of savefiles, I could use some help.

Here, a very tiny starting point:
var/safefile/F = new ("objects.msav")
You could,

client/proc/SaveObj()
var/savefile/Save
Save = new ("MapSave.sav")
for(var/obj/O as obj in world.contents)
Save << O
client/proc/LoadObj()
var/savefile/Load
Load = new ("MapSave.sav")
for(var/obj/O as obj in world.contents)
Load >> O

I am not sure if it is safe but test it out and post back if it worked or not.
In response to Super16
Well, I tried it out, and fiddled with it a bit. I ended up coming up with this last, but it still didn't work...

world/proc/SaveObj()
var/savefile/Save
Save = new ("objects.msav")
for(var/obj/O as obj in world.contents)
O.saveloc = O.loc
Save << O
world/proc/LoadObj()
var/savefile/Load
Load = new ("objects.msav")
for(var/obj/O as obj in Load)
new O(O.saveloc)

I also called this with a special admin verb for debugging stuff like this.
In response to Polatrite
Saving the objs isn't the problem... it's getting them to remember where they were and go back there when they're loaded. Something like the saving code you have already is probably enough on the save/load end... all you have to do is over ride what actually happens when each obj is saved and loaded.
obj
var //Hey dummy, variables! Er, I mean, Hey, dummy variables!
X
Y
Z
Write() //called when the object is saved.
//store the actual x,y,z, which is not saved, in the dummy variables which are.
X = x
Y = y
Z = z
..() //do the save thing.
Read() //called when the object is loaded
..() //do the load thing
src.loc = locate(X,Y,Z) //I want to go back... go back... and do it all over.