Have a question I have never seen addressed in any of the beginer books I have read. I am working on a console text based RPG, an was wondering if it's possible to save the game.
That is, get up to a certain point, exit console, then, open up console and start at that point again. I have been thinking about it a little bit, and the only thing that comes to mind is somehow saving the progress to a text file, and going from there.
Is there perhaps another method that's not beyond beginner programing, that is pointers, simple data structures etc.?
saving the progress to a text file, and going from there.
You said it yourself. Mind you, you don't have to use pure text, you can save data in binary format, although this is a little more complicated.
Basically you'll make up your own save file format and then write two functions, one that writes to the file upon exit, and one that reads the file when the program starts back up.
Obviously this is a very simplified model, but it's enough to get started.
If you're only interested in saving output/input that appears on your console, you can try the following:
1 2 3
cout << "Enter a number: ";
int m;
cin >> m;
change to
1 2 3 4 5 6
// ofstream code
cout << "Enter a number: ";
outData << "Enter a number: "; // outData is your ofstream object
int m;
cin >> m;
outData << m << "\n";
As a matter of fact, you can write a couple of [overloaded] functions that write (read) to (from) console and disk in one shot.
If you're only interested in tracking progress, you can provide keycodes at every stage. When you're starting all over, you can have the option of entering a code, which will take you to the spot you left. I would think of gotos in this scenario, because this is a text adventure and there's not much logic in it. But then again, if you can come up with an alternative, it would be better to use.