ID:154121
 
I'm looking at building a game that will start out with a richly-populated map. However, once the game is saved, I don't want objects to repopulate when I start a new session; instead, I want to load the last session's objects from a savefile. Here's an abridged version of what I've been thinking of:

1) Override obj/New() to add every new object to a global "purge" list (at least if world.time is 0; objects created after that will persist).
2) Check to see if a savefile exists.
3) If so, delete all objects in the global purge list.
4) Load game objects from savefile.
5) Begin the game.

Does this sound like a sensible way to approach the problem?
Do you save stuff and when you save, every atom that is saved gets a hasbeensaved var of 1. So you only save it once.
Gughunter wrote:
I'm looking at building a game that will start out with a richly-populated map. However, once the game is saved, I don't want objects to repopulate when I start a new session; instead, I want to load the last session's objects from a savefile. Here's an abridged version of what I've been thinking of:

1) Override obj/New() to add every new object to a global "purge" list (at least if world.time is 0; objects created after that will persist).
2) Check to see if a savefile exists.
3) If so, delete all objects in the global purge list.
4) Load game objects from savefile.
5) Begin the game.

Does this sound like a sensible way to approach the problem?

Another solution would be to build two .dmb files. The first would have the initial maps included in the compile, and world.New would save all objects to the savefile and terminate the process. The second would have no maps included in the compile, and world.New would load the savefile created by the first .dmb.
Sounds like what I use. I just create one massive savefile to store all object data, then stuff all objects on the map into there when I want them saved. Then, I mark the savefile with an exist thing that gets set to one when the world is saved.

When the game starts up, it checks to see if the savefile["exist"] = 1, and if it does that means it has been saved. If it doesn't that means the world has not been saved. If it has been saved, it deletes all objects and mobs (sept usr) and loads everything from the savefile.

I've never had any problems with that.
In response to Foomer
Foomer, could you possibly give me that code? That is EXACTLY what I need for my game, and I suck at manipulating save files. =P
In response to Garthor
Just look at the example in the Guide, that's really all you need.
In response to Pmikell
Another solution would be to build two .dmb files. The first would have the initial maps included in the compile, and world.New would save all objects to the savefile and terminate the process. The second would have no maps included in the compile, and world.New would load the savefile created by the first .dmb.

Ah, clever! I think for my purposes, the Foomerian method will be what I need -- I won't need to write turfs to the savefile (at least not most of them), and the game will be easier to distribute for others to host if I don't have to explain how to use the two .dmb files (and I'd have to remember to recompile both for game updates).

Actually, come to think of it, that's not necessary -- for distribution I'd just need the latter .dmb with a pre-existing savefile, which is no doubt what you intended. Hmm... that removes most of my potential objections. I'll have to keep it in mind!
In response to Foomer
No, really, I can't work with save files at all. I couldn't even copy out pieces of a library and get it to work. I need an exaple of saving / loading worlds. And there are none I can find =(
In response to Garthor
The example in the Guide works just fine. If you can't get that to work, mine won't work any better.
In response to Foomer
Can't find any example in the guide except for saving players.
In response to Garthor
Not sure which one you're looking at. Saving and Loading is the one I am.
In response to Foomer
But how would I make a load verb that would loop through everything in the world save file and place it on the map? That's the trouble I'm having!
In response to Garthor
give every atom/movable that you'll be saving saved_x/y/x vars, then before you move them into a list set their saved_x/y/z to their x/y/z vars, then move them to the savefile. When you load them from the savefile, locate them in their saved_x/y/z coordinates.
In response to Foomer
The problem is I don't know how to set up loading =P I know how to use Read and Write, but I can't get the >> and << to work. I'd love to have a good example =P