Inventory Prototype Issues, need help.

Started by
5 comments, last by BeerNutts 12 years, 1 month ago
I'm having trouble figuring out how to save a characters' inventory and make it accessable in a prototype that I am developing. I don't want to use a database because I am having trouble getting it to work. Does anyone have any ideas? If you do, please post. Thank you.
Advertisement
Have you tried any XML handler or just advanced persistent databases?
umm, not to sound stupid, but what is an XML handler?
An XML handler is usually a class that can load and save version compatible data in the XML format. It is easier to use XML than to hardcode version compability when saving and loading with your own file format. If you just save your raw binary data as it is without caring about version compability, the next version of your game will not be able to read the data when your new datastructure have added a variable and created an offset to everything else. XML is not good for large primitive things like images but is ideal for small files with many types of data.
If it's a very simple inventory system and you're looking for a fast/dirty solution, you could just come up with your own format and use regular text-files.

Let's say inventory consists of items (that can be represented by strings) with a given quantity.
You could then store one item with it's quantity (space separated) on each line in a text file:

sword 1
healthPotion 3
arrow 40[/quote]

That should be very easy if you're familiar with file reading!
There are probably* good C++ libraries for reading/writing something like YAML or JSON, which share the advantages of XML but are much more lightweight.

[size=2]* I haven't used these formats in C++, so I cannot recommend any particular library. Google will help you.
I'd suggest just serializing your inventory data out to disk in a simple manner, especially if it's for a prototype. Just write the number of items you want to store 1st, then write each item out after it. If your inventory data has different sizes (like strings, for example), just put the size of that piece of data before the data, and then write the rest out as bytes.

My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)

This topic is closed to new replies.

Advertisement