Multiple Inventories? 5/5 (1)

posted in: Scripts | 0

So what is the deal with blocks that have multiple inventories?

If you look at my inventory sorting scripts (Ore Sorting, Ingot Sorting or Component Sorting) you will see that in some cases I use the first inventory, and in some cases the second inventory of a block.

The reason for this is that some blocks have more than one inventory.

Examples:

  • A cargo container block (doesn’t matter which size) has only one inventory object: a list of items stored in that cargo container
  • A refinery, however, has two inventories: the first one is the list of raw ores waiting to be refined; and the second is a list of refined ores that have been produced
  • Likewise, the assembler has two inventories: the first one is the list of refined ingots/wafers/etc. that will be used to produce components; and the second is the list of components that have been produced

So… whenever you are accessing inventories, make sure you are accessing the correct one for blocks that have more than one.

You might ask: “If a cargo container only has one inventory, why is the inventory part of a list”? I can’t be certain, since I didn’t design the game, but I believe it’s a matter of standardization. All blocks that have inventories probably inherit from a class of block that stores inventories in a list (since a list is necessary if you have the need for multiples as is the case with the refinery and assembler).

From a design perspective, you don’t want to have blocks that only need one inventory (i.e. Cargo Containers) to have an “Inventory” property and blocks that need two inventories to have an “Inventory” and “Inventory2” properties. Because in the future, if you need one that has three inventories, you end up creating and “Inventory3” property and so on. It would be a bad design decision.

So to keep things standard, all blocks that have inventories have a List<IMyInventory> as their inventory property.

Just wanted to drop this little note here, so people understand how inventories are organized.

Please rate this post

Leave a Reply