I am making a game in which each player has an inventory of object instances
created from a larger table of object types. Players can have multiple
instances of the same object type. For example, one player might be carrying:
apple, sword, shield, apple, ring, ring, ring, lamp, book, sword
These objects will also have their own variables to make each item unique,
so one apple could be red, another could be green, etc.
I have made an array in the PlayerObjects table for storing the inventory, with
each item holding only a number corresponding to the key for that item in the
common table of all objects, plus the variables to determine its unique properties.
My problem is dealing with duplicate objects requested from the main table of
object types. At first I thought that I could send an array of the index values for
the player's inventory to loadKeys() and simply get back the corresponding objects,
but this only seems to work if each inventory item is a distinct item in the common
table, i.e. loadKeys() only returns one object for the first match. How can I interpret
the data returned by loadKeys() in a way that preserves the structure of the player's
inventory? Or, should I even use loadKeys() at all?
I am stumped. Thank you for any advice!