I have a fairly big (for me) text rpg that I am making, and I want to let the player save and load their progress. I have a save function which creates a file and then writes all needed data to that file. This data includes the characters name, their attributes, contents of inventory, gold, level, etc. Unfortunately, functions like read() and getline() don't work for loading that file, because they read characters, while I have strings (which can be converted to and from c-style strings) and numbers.
The save function looks something like this:
1 2 3 4 5 6 7 8 9
|
void save()
{
ofstream saveFile( "Save.txt" );
saveFile << name << endl;
saveFile << health << endl;
saveFile << stamina << endl;
//etc., etc., following same format
}
|
Load() looks like this
1 2 3 4 5 6 7 8
|
{
ifstream saveFile( "Save.txt" );
saveFile >> name;
saveFile >> health;
saveFile >> stamina;
//etc., etc., following the format, in the order these variables were saved in
}
|
I am getting a logic error: when I load the file, it confuses some variables, especially annoying is when it puts weapons/armor into spells or skills (casting leather helmet for 23 damage is terribly annoying), even though I quintuple to the power of the american national debt checked to make sure the order and the variables are all the same. I can provide the functions in their entirety, but they are quite long, because there is a lot to save and load.
Thanks in advance for any advice!