Saving the 'State' of a Console Program?

I have searched the forums and google but have come up empty.

Basically what I need to do is when the player inputs 's' I need it to save the current position in the program, and then when the player inputs 'l' it loads that position.

This is for a text based adventure game so imagine it like so:

(Narrative text here 30 minutes into the game) Blah blah blah blah, blah blah blah

1. Option
2. Option

>> (inputting 's' saves the game)

I know how to check the input to see if the player types s, I just don't know how to code the function to make it save a file that remembers where in the code that the player was.
Figure out what data in the game you need to save; for a example, current room, items on hand, etc. and save the data. When you load the game, read it in from a text file.
I am actually probably going to focus it similarly to one of those 'choose your own adventure' books. What I am looking for is a way to let the game know where in the story the player is.

After reading on the control structure "goto ___" would it be viable to do the following?:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

//variables
int iProgress

//-------------//

int main()
{

//------------//

case 'l': // lowercase "L"
     loadGame();

//------------//

BLevelOne:
cout << "BLAH BLAH BLAH";
}

loadGame()
{
     switch (iProgress)
     {
          case: 1
               goto BLevelOne;
               break;
     }
}
Last edited on
Topic archived. No new replies allowed.