Request a user's inventory from the server
requestUserItemList(username, callback)

Requesting User Item Instances

The inventory of any user can be requested by using the requestUserItemList method. This function takes a username string as the first argument, but you may pass in null or a blank string to request the inventory for the current user. The second argument is a callback function to call when retrieval is complete, which will generally involve a call to use_item or useItemInstance.

NameTypeDescription
usernameStringUsername of the user to request items for, or null for the current user
callbackFunctionA callback function to be called with the results of the operation

The callback function is passed a single object with the following fields:

NameTypeDescription
successBooleanA flag indicating whether or not the operation was successful
dataArrayAn array of item instances, if successful

Each item definition in the data array contains the following fields:

NameTypeDescription
idIntegerThe unique ID of the item instance
identifierStringThe item identifier
dataStringThe metadata attached to the item instance, if any
remaining_usesIntegerNumber of remaining uses, or 0 if this is an unlimited use item

Example: Request the inventory for the current player

kongregate.mtx.requestUserItemList(null, onUserItems);

function onUserItems(result) {
  console.log("User item list received, success: " + result.success);
  if(result.success) {
    for(var i=0; i < result.data.length; i++) {
      var item = result.data[i];
      console.log((i+1) + ". " + item.identifier + ", " + 
                  item.id + "," + item.data);
    }
  }
}