Jump to content
  • Advertisement
Sign in to follow this  
MilesPrower

Inventory Prototype Issues, need help.

This topic is 2459 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!