Sign in to follow this  
menyo

Saving rpg game data?

Recommended Posts

Hi,

I know how to save my character data, just put all the character stats in a binary file and load it whenever we wish. But i can't seem to wrap my head around saving certain map data efficiently, like chests.

Currently i'm using a separate XML for each map. So if the player leaves the map it should temporary save the chests it opened and when the player chooses to save write that to his gamedata. It might be more efficient to create a separate file with all the chests in it for each play through.

There will also be events, like defeating a boss in a castle makes NPC's move in. Should i handle this with game stages, like on game "stage 4" there are mobs and that boss in the castle, after defeating the boss the game goes to "stage 5" and i could load a new map in that place.

Stages could also be used for dialogues (which troubles me as well). Something like this:

if (stage == 1)
NPC's respond like "help us defeat the evil goblin king".
if (stage > 1)
NPC's respond like "Thank you for defeating the evil goblin king".


I'm very curious how common RPG's handle this.

Share this post


Link to post
Share on other sites
This is a problem I am also trying to resolve currently and I have come to the following conclusions.

1. Objects need to be kept in a separate global list that can be easily saved. I think avoid using level classes or map data to store objects data. Each object will maintain its own infomation (which level, position in level, other details etc.). Of course, to avoid overloading the system, you could do this only with the "important" objects in your game, leaving other objects to be static (i.e. when the user loads a game, other "objects" are reset to their original state, i.e. when a new game is created)
2. Global game state variables should be saved. Each situation will have its own flag in the gamestate array (or preferably dictionary).
3. Character statistics and inventory of course (this you have already done).

I would avoid storing level data in save games myself and am thinking of a method to achieve this. Because in the main, levels are static. Only things within the level can and should change.

Share this post


Link to post
Share on other sites
The state of the world is tied to the player's session -- that is, the player's save game file (not the character in the game). There are lots of ways to organize that -- it could be a big memory buffer where various flags and values are assigned an address within that buffer (this is how classic, cartridge-based games worked) or it could be some kind of hierarchical file structure, a key-value store, or a relational database. You don't want to modify the original map data though -- what if you have two people sharing the same PC while playing your game?

The super short version is that a player's game save file is just a collection of Boolean values and counters tracking various states and actions within the game world. Anything in the game world that needs to persist between sessions (eg, whether the player has defeated the goblin king) must be represented directly in the save file, or derived from data in this save file.

Share this post


Link to post
Share on other sites
I saw a interesting way to handle this.

Basically you treat NPC speech like a scripting language where responses are based on tags where you have a vector/list/whatever of tags where you have a string and a value.
like:
string = "GoblinKingDeafeated" value = 0;

And then when your adding speech for that specific NPC just check the variable (in your vector) for whatever value. This allows you to do whatever you want for instance you could have multiple responses based on how many objects were collected.

string "PlantsGathered" Value = 4;
If "PlantsGathered" > 4 NPCSAY "Thank you I have enough plants to make my stew"
else if "PlantsGathered" <= 4 NPCSAY "You still need more plants for my stew"
else if "PlantsGathered"== 0 NPCSAY "I need plants for my stew go check to the north near the old cave"

Anyway just my thoughts.

Share this post


Link to post
Share on other sites
Little late reply but i have been busy past week. I'm using XNA/C# and getting familiar with storing data, i just want to know a effective way of storing particular data (indeed not shared between sessions).

I'm still a bit in the dark here. Let's say a user loads a game and he opens a chest, now i should store this in a temporary file (since the user has not saved yet). Then when the player saves add this list to his already saved data. For chests i can just add it's ID to the list. Then when i load a map it should lookup this file to see whenever a chest has been opened.

Should i add a scripting language to handle dialogues, build my own or just add it in using binary data? What i currently have in mind is something like giving each NPC a location ID and a class ID. The location ID is for each different town/area. The class ID is for the different dialogues, like the king says something else then the inn keeper. Location ID is somewhat linked to the stage, like so:

Player creates a game and goes immidiatly to the 2nd town, there he talks to a NPC.

if (stageID < location ID)
{<town> needs your help}
if (stage == locationID)
{
if (classID == king)
{Show text of king}
if (classID == commoner)
{Pick from commoner texts}
}
if (stageID > locationID)
{
{thanks for the help}
}

This however limits me to have only one stage per town, or at best 1 stage per NPC. I also would like to have a initial text when you first speak to a NPC like "I haven't seen you around here", and maybe even somehwat hidden quests where you have to talk to someone like 10 times.

My way just does not seem efficient and effective, i'm really looking for better ways of organizing this.

Share this post


Link to post
Share on other sites
Rayvne already basically covered it, its really just a giant dataconstruct of boolean states.

Give every world object a unique ID.

Create a Dictionary<ID,State> if you want to have a complex State object, or simply DIctionary<ID,bool>. Then whenever a thing's state changes, update the dictionary. On load of an object, check the state. World state would be saved as part of the users saved game, not in the world itself.


The only gotcha is IDictionary isn't serializable, but that is [url="http://msmvps.com/blogs/rakeshrajan/archive/2006/01/15/81105.aspx"]easily handled.[/url]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this