C# Multidimensional Collection to Store and Retrieve Character Information

Hi guys,

I’ve been reading up a lot on Unity3D. Although I have a strong web development (PHP, MySQL, JS) background I chose to go with Unity C# instead of Javascript due to my dream project possibly requiring use of a third-party network suite that supports Unity3D.

I’ve been playing with Arrays/Collections for the last two days almost full-time and I’m up to speed with how to work with them for the most part. However, I’m a little uncertain about some concepts especially multidimensional collections. Its likely I’m at a disadvantage owing to my non-programmer background and being spoiled by the flexibility of PHP arrays.

Following is what I came up with. However, is that the right way to go about it? All I know is I want a string INDEX and the value needs to be of any type.

Dictionary<string, Hashtable> myPlayer = new Dictionary<string, Hashtable>();

myPlayer["DATA"] = new Hashtable();
myPlayer["DATA"]["Health"] = 100;
myPlayer["DATA"]["Mana"] = 100;
myPlayer["DATA"]["Speed"] = 6;
myPlayer["DATA"]["Gold"] = 70;

myPlayer["CUSTOM"] = new Hashtable();
myPlayer["CUSTOM"]["Gender"] = "Female";
myPlayer["CUSTOM"]["Style"] = "Gamma_H03";
myPlayer["CUSTOM"]["Face"] = 1;
myPlayer["CUSTOM"]["Body"] = "Medium";
myPlayer["CUSTOM"]["Suit"] = "Alpha_S01";
myPlayer["ITEMS"] = new Hashtable();
myPlayer["ITEMS"]["Potions"] = 5;
myPlayer["ITEMS"]["Food"] = 10;
myPlayer["ITEMS"]["Bolts"] = 20;
myPlayer["ITEMS"]["Stones"] = 3;
myPlayer["WEAPONS"] = new Hashtable();
myPlayer["WEAPONS"]["Range"] = "Crossbow";
myPlayer["WEAPONS"]["Surround"] = "Bomb";
myPlayer["WEAPONS"]["Combat"] = "Knife";

What is the best practice to store and retrieve character information in a massive RPG with heavy character customizations and such like the above?

Your approach will work.

However, I must say I’m a huge anti-fan of using strings and any-types together. While it works, it’s impossible to make it maintain itself. YOU have to remember the exact strings required to access any specific item, and if YOU becomes YOUR TEAM or FUTURE YOU then you’re not gonna have a great time (I used blender python… it suuuucks trying to relearn the strings!)

I highly, highly recommend you use custom classes wherever possible, for type safety, autocompletion, and compile-time rather than run-time error catching. I’d build a class for “An Item”, for example, and “A Player” would have an array of "An Item"s.

If you still need anytypes inside your custom class, at least they’re limited in scope.