Text based game - Save progress

Hello !

I am making a text-based game where you pick a character to talk to and you ask them questions and they answer, etc. The output would be similar to this (the [] would be user inputted):


Who do you want to talk to ?

1. ???
2. ???
3. ???
4. ???

3
You Picked ???.

"Hello, can I help you?"

1. I just wanted to chat.
2. My name is [ ]. What's your name?
3. So what's there to do around here?
4. Do you know how I can get to [ ].




I looked around a little but I was unable to find a solution. Basically, I wanted to know how to save progress to come back to a specific point in a conversation. So if someone stopped at picking ??? (number 3), they could save, come back, and see the same choices again.

Links and referrals are very much appreciated! I'm not looking for anybody to do this for me (unless you want to share of course).
Last edited on
That is really depend on how your game is organized. As telking is main action of the game I really hope you have something like state machine here or it will be hell to maintain.

In case of state machine, you should save index/name/whatever of current state (not pointer, as they wil be invalidated on restart) and all "global" game variables to the file.
I actually don't have a state machine, thank you very much for that tip! I'll look into that.

Thanks for all the advice!
I was wondering, if I didn't want to use a state machine, how would I go about use fstream to save every line of output (the user's choices) or is that just asinine and/or impossible?

Edit: also could someone please direct me to a good reading source about state machines? I can't really find anything myself.
Last edited on
how would I go about use fstream to save every line of output (the user's choices) or is that just asinine and/or impossible?
The problem is, what should happen if you select saved choice? Where and how will you store actions? What about global state of your adventure? If you can answer those question, you can implement saving your way. But just think what will happen when you will have about 100 locations (a small amount for even small-sized game)?

Here is a thread on codereview which may address some of yours isues: http://codereview.stackexchange.com/questions/49614/text-based-adventure-game-with-too-many-conditional-statements
Notice that top answer uses something like state machine represented as directed graph.

also could someone please direct me to a good reading source about state machines?

http://www.gamedev.net/page/resources/_/technical/game-programming/state-machines-in-games-r2982
http://gamedevelopment.tutsplus.com/tutorials/finite-state-machines-theory-and-implementation--gamedev-11867

Also you may check AI game engine programming or Programming game AI by example books
Thank you very, very much for all your help MiiniPaa, I really appreciate it!
You can avoid that state machine if you use a proper desing
Yes, you can avoid state machine doilerplate if you just remember that it can be easily represented by directed graph. And text games can be represented by ordered graph too, where nodes are locations and edges are choices.

You can create a graph (using something like adjacency list) and manually move player position in it. WIth proper design it is no harder than state machines, and allows you to make data-driven games too.
Here is how one text adventure game looks in editor: http://puu.sh/9KNF6/47388c3f96.png
@MiiNiPaa

I see! That seems visually easier to understand probably make it simpler to make changes in the long run. I was wondering, what editor is that?

thanks again for all your help
what editor is that?
TGE, text quest editor for Space Rangers. Does not have Engish version IIRC.
Topic archived. No new replies allowed.