Need some ideas about how to store core game data.

Hi, this question is not about saving/loading games but it’s about how to store core game data.

With ‘core game data’ I am referring to things such as:

  • Dialogue lines
  • GUI descriptions
  • All other text
  • Monster statistics, HP etc.
  • Etc.

I’ve seen a MySQL type of database being recommended for save/load game data. Would that be also the way to go to store other data?

Or am I being completely wrong with my approach - should every game object have (in its prefab etc.) its own data in it, rather than them being read from somewhere else?

This question came to me while I was scripting my GUI. I made tooltips / windows etc. so there are a buttload of lines of text in my GUI script files (.cs etc). I’m not very experienced with game coding and I felt like this ‘core data’ should not exist in scripts but somewhere else and be read & loaded from there when necessary.

Thanks!

For heavy amounts of text, might be an idea to use XML or JSON. JSON would require finding a third party parser, but you can use System.Xml for XML.

I like this quote:
“XML is like violence. If it doesn’t solve your problem, you’re not using enough of it.”

It probably points to it not being the best solution but I find it perfectly adequate. I’ve done quizzes and the like using XML and Unity.
Or you could just stick it in a text file.

Since you’ll be populating these as well, then you should use a format that makes it easy for you to modify.

Probably the easiest way would be to create a C# script file, which will have a bunch of static variables with all the data you need:

public class DialogLines {
    static public string welcomeDialog = "Hi, welcome to the game";
}

public class MonsterStats {
    static public int gremlinHealth = 30;

}

Then you can access these anywhere in the code:

public class Gremlin : MonoBehaviour {
    private int health;

    public void Start() {
        health = MonsterStats.gremlinHealth;
    }
}

The advantages of this trick is that it’s easy to modify since you have everything in one central place, and it’s easy to access, you don’t need to do any parsing.

The drawback is that once it’s compiled you can’t change it. So if you want to let your players modify these for example, they can’t.

The next way to go is a text file. Either XML, Jason, CSV, or even a simple “key=value” format will work. You’ll need to write a parser to read this though, many tools exist out there for the common formats, but you still need to do some parsing work to find the correct values you need.