Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

What is the best way of storing the character's inventory (consisting of each item having a value for type and quantity). The only methods I can think of is to use the "text" type of field then parse the value from that whenever the inventory is loaded. Is there a better method or data structure?

share|improve this question
    
can you just give an overveiw about your game? is it going to be browser-based or is there going to be client application? how many client may connect to your server? what language are you using server side? –  Ali.S Jun 4 '11 at 14:18
3  
I'd say "text" is the worst choice. Build up relations between "item" and "player" tables... overall, this is probable better asked over at: dba.stackexchange.com –  bummzack Jun 4 '11 at 14:40
    
Thanks for the advice. I wasn't aware of dba.stackexchange.com - obviously that would be a better choice! –  jSherz Jun 4 '11 at 17:13

1 Answer 1

up vote 5 down vote accepted

Read up on standard database design. Specifically normalized forms. An approach would be to have 3 tables:

character having a character_id and other data

items having an item_id and other data (names, weight etc...)

inventory having character_id, item_id, quantity.

A player's inventory could be expressed as "SELECT items.name FROM items, inventory WHERE inventory.character_id = 'THECHARSID'" Of course based on your other questions I'd much more likely suggest using an ORM that handles this for you. Look at Relationships, and backrefs in something like SQLAlchemy.

If you need the concept of inventory 'slots' then that's another column in the inventory table. (IE: Character 32423 has an item of type 832 in slot 0 (The head slot)) If each item has unique stats (Durability/upgrades) Then you can do something like the item table contains the item specific data, and has a link to an item_base column that defines the base stats that all items of that type have in common.

share|improve this answer
    
Thanks for the help. I shall look into ORM and SQLAlchemy. –  jSherz Jun 4 '11 at 17:14
2  
If you're still deciding which SQL server product to use, be sure to take a look at PostgreSQL (free and open source, which has a community that is heavily populated with optimization nuts) -- since you may need to have multiple servers, you'll probably be interested to know that PostgreSQL now has built-in replication features and has been well-suited to handling large databases in high-demand environments for a long time: postgresql.org –  Randolf Richardson Jun 4 '11 at 18:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.