Forum BigDB linked inventory tables

Discussion and help relating to the PlayerIO database solution, BigDB.

linked inventory tables

Postby HandyLanguageLabs » October 1st, 2013, 2:54 am

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!
HandyLanguageLabs
 
Posts: 3
Joined: June 28th, 2011, 12:45 am

Re: linked inventory tables

Postby Benjaminsen » October 2nd, 2013, 8:26 pm

Loadkeys is the right way to go. It's basically the best direct way to do a lookup in BigDB.
For your specific use case, you need to do a data merge in code post loading the inventory items.

E.g. you loop inventory once to get unique key's, on success you loop inventory again to merge inventory with the loaded data.

Great way to do an inventory btw.
Benjaminsen
.IO
 
Posts: 1444
Joined: January 12th, 2010, 11:54 am
Location: Denmark

Re: linked inventory tables

Postby HandyLanguageLabs » October 2nd, 2013, 8:33 pm

Thanks, I will try this!
HandyLanguageLabs
 
Posts: 3
Joined: June 28th, 2011, 12:45 am


Return to BigDB



cron