How to store large amounts of Text?

Godot Version




I am currently facing a question I cannot answer myself. I want to create a text adventure. This means long, elaborate texts that can be easily translated into other languages if possible. Additionally, the player can revisit locations, so the texts need to be dynamic.


First Visit: You enter a dark cave.

if has_lantern(player_inventory) is false: ...

Unfortunately, it is so dark that you cannot see anything. Something seems to be lying on the ground, but you do not dare to reach for it.

Second Visit: You enter a dark cave.

if has_lantern(player_inventory) is true: ...

You can clearly see that the cave extends deep into the mountain. There is a small chest lying on the ground.

How can I efficiently store such texts, which can be very long and detailed? It does not seem right to hardcode them.

Any ideas?

It would be better to create or use a dialogue engine.


I’ve been looking around for solutions this as well… it seems like lots of devs are writing strings into spreadsheets, converting them to .json or .xml then importing them. This video is about creating items, but I’ve also seen text done this way, with each column being a different language.

That doesn’t solve the problem of having to type entire books directly into the source code, which makes it practically impossible to maintain an overview. Each text would then be directly in the code for every translated language. How I display it in the end is not the question, but rather where I store it. This should allow me to include scripting within the text or use BB code (or similar) to display text in bold or italics.

A good dialogue engine is built to read separate text files, you would not be typing directly into source code. The dialogue engines I have created read a file line by line, the default action is to display the written text; other actions are simple like checking or setting variables, and jumping to other pages of text. That’s the barest of bones and it’ll get you very far, you may want to include actions for checking inventory items, removing and adding inventory items.

If you arent familiar, it is worth looking into virtual machines. This pattern is a lot of work, you are essentially creating a compiler and executing it’s code; but with a small command set you reduce code while keeping flexibility.