Storing objects in a text file, advanced arrays

Greetings.

Is it possible to make jagged arrays/lists/dictionaries (or some equivalent), then save it to file/load it?

I’d like to store all the items within my game in one of those three.

High-level, it’d look like this:

[LNG_SWRD01]
    [NAME = LONG SWORD]
    [DAMAGE = 70]
    [PRICE = 700]
    [SPECIAL ABILITY = 5]
[LNG_SWRD02]
    [NAME = LONG SWORD]
    [DAMAGE = 90]
    [PRICE = 1300]
    [STOLEN = TRUE]

And so on, and so on. Maybe sort it according to some IDs for easier searching?

So, basically, I would like to store an indefinite amout of items in some array/whatever (I’ve heard lists are better) that I can look up and edit, as well as an indefinite amount of different properties stored “inside” each item. Note that each item would have different property categories, so even if some traits would be the same (first goes name, then some general type maybe), later it would be different. Not like first is always name, then damage, then if it got stolen, then price et cetera.

It would also be cool to be able to add items run-time (let’s say you’ve just made a custom sword, so you add an item [CUSTOMSWORD01] and then define its properties.

Oh and also, how about structs here?

Thank you so much for any answers!

Use XML for saving and loading data. .NET/Mono has great support for XML manipulation.

1 Like