Jump to content
  • Advertisement
Sign in to follow this  
Stavros Kokkineas

ideas for branch tree story program

This topic is 2477 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok, so as I have said I'm making this text adventure game so I learn the basics of programming. After overcoming the problem of reading texts tat contain argument tags for the name, age, weight etc. of the character I know have another "problem".

I want to have brach story trees in the game meaning that if the player makes for example the A choice a story is described, if he makes a choice B another story unravels and so on. Right know I have a repeating code which I don't like very much wich chenges the "flag" of the file and I use the flag to read the corresponding document that;s in the file. Meaning something like this:


void branches (char c){

cout << l << l;

// Introduction

if (flag == "Introduction.txt" && c == 'a') { flag = "Intro A.txt"; }


else if (flag == "Introduction.txt" && c == 'b') { flag = "Intro B.txt"; }



// Rebels After Start

else if (flag == "Intro B.txt" && c == 'a') { NAME = "Aenaeas" flag = "Name - Ok.txt"; }

else if (flag == "Intro B.txt" && c == 'b') { flag = "Name - Noone.txt"; }

else if (flag == "Intro B.txt" && c == 'c') { getName(); flag = "Name - Ok.txt"; }


// Rebels After Peblo

else if (flag == "Intro A.txt" && c == 'a') { flag = "House_Not.txt"; }

else if (flag == "Intro A.txt" && c == 'b') { flag = "Rebels_after_Peblo.txt"; }

else if (flag == "Intro A.txt" && c == 'c') { flag = "Saritonae_Not.txt"; }

else if (flag == "Intro A.txt" && c == 'd') { flag = "Limbordo_Not.txt"; }

else if (flag == "Intro A.txt" && c == 'e') { flag = "Gavrama_Not.txt"; }

else if (flag == "Intro A.txt" && c == 'f') { flag = "Castle_Not.txt"; }



// Exit

else { flag = "Exit"; }

story(flag);
}////////////// branches


And this is just the first two choice inputs. Can anyone think of a clever system where I can kind of do the above process automated?

I really can't think of really smart way of naming the files and understand what they are about and also have an automated read system according to current and previous choices of the player. Is there such a way or should I just change the design of the game?

Share this post


Link to post
Share on other sites
Advertisement
The keyword is "data driven design": You don't want to write the story in code but in data.

Assume that each text file you are loading has a structure as follows:
1. Each line that starts with "branch:" encodes a branch. E.g. "Introduction.txt" begins with the 2 lines
branch:a=Intro A.txt
branch:b=Intro B.txt
2. Each remaining line up to the end-of-file is treated as regular text which has to be displayed for the user.

Obviously, when reading the file, the program checks for lines that starts with "branch:", divides it up into the choice (after ":" and before "=") and the filename (after the "=") and stores this into a map with the choice as key and the filename as value. Then it displays the text.

When the player inputs a choice, then the program makes a look-up whether the choice is stored as key in the map, and if so it uses the associated value as filename to continue the story.

There are some details to be worked out, of course, but the above should give a hint of how to do something like you've requested. Later on you can assemble all the small text files into a big one, using additional lines as anchor points.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!