Efficient ways of iterating through text files

Godot Version

Godot v4.3

Question

Good morning, afternoon, evening, etc.

On the way of optimising project resources, I came up with a dialogue system that I think works really well for me. In one single line consisting of an array, you store information needed for the dialogue to display all the info it needs in a solid structure (what sounds? What text? What effects? What frame? etc).

I thought “hm, maybe I can do this on a .txt file”, but testing a bit I found that in order to get this information, Godot will iterate through every line. Given my project’s hefty amount of dialogues (hundreds, I don’t know if even thousand), I figured it might be a bad way of doing it.

Researching, I found “json files”, but their rigid structure doesn’t sound well to me.

Still, I need help with this. What system should I use? txt? json? Any other in particular I might want to look out for?

Thanks!

JSON maybe isn’t so bad. It will have conflicts with quotes (ie, you will have to escape them), but once you get used to it, you may find it a really valuable tool.

I have never tried what you are doing before, but I’ve worked with a lot of data.

You may want to consider CSV, which any spreadsheet can open. And then convert your CSV to JSON. This way you can use a spreadsheet to manage your data instead of working in messy text files directly.

1 Like

I would also recommend sticking to JSON.
You can maybe also consider creating a custom Resource type to hold your values.

1 Like

Alright, thank you lots!