(Photo) How could I find items separated by stacks within my inventory to craft another item?

End of day how you do something is dependent on the structure of the data being read and modified. I have a Database Administration (DBA), Software/Web development background. I organize data the way I would for a large relational database.

Arrays, TMaps, Structs are in a simple comparison basically DB Tables.

Key-Value Pair

  • 0: some value
  • 1: some value
  • 2: some value

Or

  • Parent ID (Key), {Element: Value, Element; Value}
  • Parent ID (Key), {Element: Value, Element; Value}
  • Parent ID (Key), {Element: Value, Element; Value}

Data Tables are in essence a database table built from structs (column name and type).

Parent ID (Key) would be Row Name, Requirements a Column.


Inventory systems are mainly organized simple data. Name of thing (Key/ID) and how many. Complex data for “things” such as mesh, icon, stats/specs is typically stored in a data table using a Name type for look up and retrieval. That being said most setups should be based on a Structure of data that’s easily read and updated.

Best practice is to fully scope out the “Things” you can have in an inventory and then group them into types. Craft components, Consumables, Ammo, Healing, Weapons… Doing so will allow you to simplify the data as much as possible. Such as creating a dedicated inventory structure for each Type. Small sets of things are easier and faster to update/read, than large sets.

For crafting items you need data to tell you what crafting components are needed and how many of each. The simplest structure would be… Item Name/ID, Quantity

Bandages:
Cloth, 3
Can Tab, 2 (metal clips to hold bandage wrap in place)

For this you’d use a Struct array.

If you go the Type groupings route your struct would look something like the following.

image

This structure contains an Enum to tell your code which container (Array, TMap, Struct) these inventory items are stored in.

Example

Each Container would hold Inventory Data for the Type.

image


Validating you can craft and then crafting results in something like…

image


Going the Type Groups route “Can” increase the amount of code depending on the containers structure. You’d have to create a dedicated function/macro for each group type that varies. Yet the functions themselves should be lightweight, thus negligent.


Example functions output Item Name and available Quantity for UI presentation. Say you want to create a Bandage but don’t have enough of something. That information should be presented to the client.

Anyway, this is just food for thought. Hope it’s helpful.