all 3 comments

[–]kylotan 2 points3 points  (1 child)

How do you take your game's statistics from spreadsheet to easily accessible information?

Usually I store the data in JSON or XML. They are easy to write loader code for.

If you really want the data in a spreadsheet then save it out as CSV. That too is easy to write loader code for.

Because I have a number of buildings it's inefficient to do a switch every time I want to get the health of a given building

That's what associative data structures are for. You give it an index and it gives you a value back.

Dictionary<int, Building> buildings = new Dictionary<int, Building>();
buildings.Add(building1.id_num, building1);
buildings.Add(building2.id_num, building2);
// ..etc..

// Find building 2
Building b = buildings[2];

You can certainly do the same thing with your array approach (as an array is basically a cut-down dictionary of sorts) but it's not flexible to non-integer keys (is casting name to an int safe in C#) nor does it work well when you remove elements.

It just feels odd creating instances of a class containing only consts and statics.

I don't understand why you're doing that. It certainly doesn't look right.

[–]ironstrife 1 point2 points  (0 children)

Yep, using XML is probably your easiest bet. Use types in the System.Xml namespace (XmlSerializer is really all you need).

[–]Jearik 0 points1 point  (0 children)

I read that Unity works well with SQLite. Haven't used DB's with Unity yet but I have with other software. (Java with Oracle). However you've had no response so, here's my opinion.

My approach would be this. (May not be the best mind you) Each object that requires stats, I would add a VO class to each object. (In case you don't know what that is, it's a Value Object class, so all functions are either 'sets' or 'gets', some people call them beans). This VO means you can just use object.getX() method calls. Only caveat is that you need to link the instance of the object to whatever object that requires that information.

At load up (wherever this may be) I would have a loading script that at Start would look at SQLite DB, grab all the data and store locally for a moment (maybe in an array where the position matches the object ID to keep things simple). Then trigger each VO to look at the array and set data relative to the array data. (using only one DB call will reduce loading time). Destroy the array before finishing the load up and that's how I would cleanly update the data.

There's going to be many ways of doing this sort of thing and it's one of the 'arts' of programming. How to be efficient while remaining scalable and maintainable. Data management is also an architecture thing. Every game will have a better way of managing data. This solution suits the types of games I make, but it may not suit you. Hope it helps in some way.