I am working on a small game, I need to add an unlimited inventory to the game but I am not sure how to do it.

I have an inventory system with a specific amount of slots, here it is:

<?xml version="1.0"?>
 <username> XXX </username>
 <password> XXX </password>
 <slot1> X </slot1>
 <slot2> X </slot2>
 <slot3> X </slot3>
 <slot4> X </slot4>
 <slot5> X </slot5>

I am open to switching to SQL or another data storage system, but I need a solution that would let players have as many items in the inventory as they would like; with no limit.

  • \$\begingroup\$ You can have arrays/list in xml. And you can have List in C#. \$\endgroup\$
    – Kikaimaru
    Sep 4, 2013 at 13:16
  • 2
    \$\begingroup\$ I'm really not following the problem here. Do you just not know how to put a list in C#'s XML serialization? \$\endgroup\$ Sep 4, 2013 at 17:02
  • \$\begingroup\$ It should be pretty easy in SQL. You just need to make a Player table (with a player ID # as the primary key), Item table (with an item ID # as a the primary key), and an inventory table (which has foreign keys to the player ID# and item ID #) \$\endgroup\$ Sep 4, 2013 at 17:20

2 Answers 2


You'll want to use a List. Probably a List<InventoryItem> or similar.

The documentation for List<T> is here.

Here is a set of answers on how to serialize a list to XML (you didn't say how you were saving your XML - this link gives you some options).

An XML file can store the list of items "inline", so it might end up something like:


On the other hand, if you switched to a database (using SQL), the traditional way to store something like this would be to have player table (with a "key" value, like an ID number) and a inventory table for every item in the game - each having an "owner" value that matches the ID of the owning player.

You would then use SQL to query for all the items in the inventory table owned by a given player (ie: having the matching ID). Something like:

SELECT item_name,item_whatever FROM inventory WHERE owner_id = <whatever>

The correct solution probably depends on the scale of your game. But if you're unsure - go with the XML to begin with - it is easier to implement - you can alway change later if the need arises.


Theres two basic ways to do this:

  1. The Magic Bag
    Containers themselves have fixed sizes, but there's no limit to your ability to put "bags" inside other "bags". Thus the only practical limit on your inventory is your ability to get more "Bags"

    This has the advantage that containers have fixed capacity (which might be easier to implement), and that you can "throttle" players inventory capacities by controlling the price or availability of extra "bags".

  2. The Holdall
    This seems to be closer to what you are asking for; the player has a single "main inventory" of essentially infinite capacity.

    This has the advantage of minimising overhead and micromanagement for the player, though might complicate implementation depending on you game's structure.

in either case, you will need to be familiar with your programming languages' relevant List or Array types.

As for storage, your problem is simply that you feel the need to specify carried (but not equipped) items as being in specific slots; this is completely unnecessary. in XML, simply have multiple <item> tags. This is perfectly legal.

In SQL-based databases, the main solution that I've seen is to have a table of items, each of which has field denoting who "owns" them, or what "container" they are inside.
This is trivially queryable.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .