question

hampusbankler avatar image
hampusbankler asked

Get an item with certain InstanceId from inventory?

In cloudscript, I'd like to get the item instance with a certain instanceId from the player's inventory, to read some custom data from it.

My question is, what's the best practice here?

I guess that I could use server.GetUserInventory(), and then iterate over the items, look for a matching InstanceId, and then read the stuff I need.

But is there something like a server.GetUserInventoryItemCustomData() or a server.GetUserInventoryItem() that I'm just missing?

Best, Bankler

Player Inventory
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Joshua Strunk avatar image
Joshua Strunk answered

Your guess is spot on. If you need to do more than a couple item lookups though you can always build a dictionary object using the InstanceId as the key and the ItemInstance as the value. This is also the recommended way for looking up catalog items.

Related:

https://community.playfab.com/questions/15298/getting-an-individual-item-instance-using-the-serv.html

1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Steve C avatar image Steve C commented ·

This doesn't feel all that efficient. Having to iterate to get a singular item makes for a messy code base. Was there ever a singular lookup added?

server.GetUserInventoryItem()?

1 Like 1 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.