ID:179506
 
I'm not sure if this can be done, but I think it can.
I'm trying to save a world state when the world closes ( Del() ) and reload it's info when it is started again ( New() ?). Currently I have it saving no problem, but loading is producing a problem. I can't change constant data (or so says DM). Basically, when I save I use
world_save["world"]<< world

and loading is
world_save["world"]>> world


I'm not sure I'm doing it right, becuase I'm still relatively unfamiliar with savefile (Using Deadron's tutorial in the FAQ atm). If it's possible to do what I'm trying, please let me know what I need to change.

Thanks

Sapphiremagus
sapphiremagus wrote:
I'm not sure if this can be done, but I think it can.
I'm trying to save a world state when the world closes ( Del() ) and reload it's info when it is started again ( New() ?).

You can't save and load the world.

You'll need to decide what data you want to save and save that.

However, in general saving the entire state of your game at once is likely to be a rather lengthy and inefficient approach. Usually you want to segment the chunks of data and save them separately at different times.
In response to Deadron
Hmmm, alright. Then how about this. I mostly want to save the variables of the objects in the world that players might change, such as changing a lock, setting a name, opening doors, etc. Should I use for(var/object/O in world) and do the saving that way?

<font color =#0000FF>Sapphiremagus</font>
In response to sapphiremagus
sapphiremagus wrote:
Hmmm, alright. Then how about this. I mostly want to save the variables of the objects in the world that players might change, such as changing a lock, setting a name, opening doors, etc. Should I use for(var/object/O in world) and do the saving that way?

More evidence that I should dust off the old map saving/loading code...

In the meantime, yes you could take that approach. Assuming you won't have a huge number of objects, one way would be to put all the objects in the world in a list, then save that list to the savefile.

I don't believe that the location will be saved for those objects, so you'll need to add a few lines of code to save and restore the location in the object's Read/Write procs:

obj
Write(savefile/F)
// Remember where I was.
F["x"] << x
F["y"] << y
F["z"] << z
return ..()

Read(savefile/F)
// Let the rest of me get read in first.
..()

// Now get my location and put me back there.
var/my_x
var/my_y
var/my_z
F["x"] >> my_x
F["y"] >> my_y
F["z"] >> my_z
loc = locate(my_x, my_y, my_z)