I’m working on a game project and it will contain dialogue and notes about the story.
To store all this text I was thinking of using external .txt file.
Is it possible to read a text and find variable I need inside a text file organize like below ?
XML or ScriptableObject databases would be my suggestion. You’ll have to do some research for either though, they aren’t exactly something you can stumble through (intermediate level programming).
Either of your options are possible, but frankly using a text file (not XML) in that manner would be more difficult than just using XML- harder to parse and easier to mess up on. The latter (custom class) is likely going to be used regardless of which method you pick, because that’s how you’ll probably store the information once you’ve read it back into the program from the file.
You can use the second one directly, if you want to populate your variables in a Start() function or something, but I don’t recommend that. You could also use it more directly by making a prefab and slapping a one-time script on it that has a list of public serialized MyNotes objects. Then you can populate the list in the inspector and use the prefab like a database. This was one of the primary methods of storing large amounts of information internally (no external files needed) before ScriptableObjects were created as an alternative.
I was thinking about this, I used this method to store items, I had a prefab in my scene with a script I could populate with items and their properties, same as you say ?.
Yep, that’s how it works. You’ll never instantiate the prefab or actually have it in the scene, you’ll just reference it in scripts by dragging it onto “database” slots where needed and then accessing the data that way. This was a very common method before ScriptableObjects, and it’s far easier because ScriptableObject databases tend to have custom editors which can be time-consuming to create.