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?
|
|
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. |
|||||||
|