Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android, Storing and retrieving Text

I'm currently working on an Android application for my college, let me give you a swift presentation:

There is a story which the player can read, and then he will have 3 choices, he will choose one, and another story will show up with 3 choices again and so it goes on... (But every choice lead to a complete different story)

As you can guess, i have a lot of text to store, to class and to retrieve. The first page shows the first story and 3 choices, if the player chooses and clicks on a button, the following story will appear but it can also mean the end (obviously if i always keep 3 paths X 3 paths X 3 paths... it's going to get complicated)

_______________ What I was thinking about ____________________________

So my first guess was to use an xml file, one with every story and another with every choice.

At the opening of the application, i would use a parser to run through the file and put every string in a Tree Structure. (so one tree for the stories and another for choices I suppose)

I wanted to use number to structure it, for exemple, if you are currently on 1 and you click on choice 2 then you put another 2 at the end of the previous story, it will become 12, and then if you click on choice 3, it become 123 etc... I though it was easier for the tree, alas, xml only give a tag name so i wanted to use story1, story11, story12, story13 etc...

What the structure of my xml should look like (or my tree)

But it's already bothering to class it in a tree since i wanted to use numbers, I have to get a String with parser.parName(), and then I need to substring to get the number at the end, and just to retrieve in what node it should go take some ressources.

In other means, the more I think about it, the more I come up with complicated ideas, so I need some smart people to tell me where to go. (I have clearly lost myself on the road)

__________________________________ My question ____________________________

If you feel like this smart one, here is my question

What would you use to store the text? an Xml file? would you use a tree after that? And how would you do that, to efficiently class the xml into the Tree?

I can see that my explanation is a bit messy, so please tell me if they are something you don't understand. (or if it is my broken english)

Thanks for answering !

like image 776
FloLp Avatar asked Feb 02 '26 13:02

FloLp


1 Answers

Personally, I would put each scenario in one JSON file each and each choice has a key that points to the next filename if there's no need to translate any of your assets. You can load the first file (or last save) at runtime. The file name of the scenario would be the "save" itself.

However, if you need translation for any of your story lines, you may want to dump it in "strings.xml" and then create the tree at runtime with references to the respective R.string ids. The R.string id should not be used as a save in this case however, as it can change between compilations. Each story scenario should probably have a scenario ID that should never be modified (an enum would do it)

like image 108
Kenny Byun Avatar answered Feb 05 '26 02:02

Kenny Byun