Storing data in Text file vs. Script

So I’m working on a game that contains 60 star systems. Each system contains between 1 and 6 planets. Every planet has a type (eg. helium, hydrogen etc.), a name etc. and so I have a lot of data that I need to handle. Some data, such as how much money has been invested in a system, will change throughout the game.

In terms of good practice and ease of use, is it better to dump all the data to a text file and use StreamReader to get the data at runtime and edit it on the fly, or would it be better to actually have all the data contained in the scripts (as public variables, so that I can assign the script to each system object and edit it as I go).

Sorry if this isn’t specific enough, I am happy to extend on what I’ve written if needs be. :slight_smile: Coding in C#.

Thanks.

There’s actually no problem storing such configurations in JSON / XML / custom format files within the assets folder. In this case the text is packed along with all other assets into resource files. The security reason thef1chesser mentioned is quite irrelevant, because it’s actually more complicated to change values in a resource pack than in your code :wink: (Unity-3D-Obfuscator + ILSpy)

Or course if you plan to load those stuff from an external file, it’s quite easy to modify the values. Keep in mind that you can’t prevent cheating in singleplayer games and it’s quite a bit of work to get it more or less safe in online games.

If it’s a singleplayer game you might want to encrypt your text file in your release. This can be beaten quite easily if you know how, but it would prevent most scriptkiddy cheating.

Great advice! At the moment I’m just prototyping the game so fool-proofing it is not top priority (but I really appreciate the tips!), I just didn’t want to get halfway down one route (streamreader/scripts) and realise it’s a massive pain in my bum. I’ll have a read up on JSON and XML formats to see if they will do the job better. Thanks very much :slight_smile: