question

Cricket_FeVR avatar image
Cricket_FeVR asked

How to print certain items from the inventory i.e items of particular class or tags using unity from server side? Can someone paste the code?

How to print certain items from the inventory i.e items of particular class or tags using unity from server side? Can someone paste the code?

PlayFabServerAPI.GetUserInventory(new GetUserInventoryRequest { PlayFabId = "playfabID" },

result => {

result.Inventory.ForEach(item => Debug.Log(item.ItemInstanceId + " : " + item.DisplayName)); },

error => { Debug.LogError(error.GenerateErrorReport()); });

Player DataapisPlayer 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

·
JayZuo avatar image
JayZuo answered

You can use FindAll method for query easily. When you say "particular class", I'd think you mean ItemClass in ItemInstance. If so you can use some code like the following:

        PlayFabServerAPI.GetUserInventory(new PlayFab.ServerModels.GetUserInventoryRequest { PlayFabId = Id },
            result =>
            {
                result.Inventory.FindAll(item => item.ItemClass == "XXX").ForEach(item => Debug.Log(item.ItemInstanceId + " : " + item.DisplayName));
            },
            error => { Debug.LogError(error.GenerateErrorReport()); });

However, there is no tags in inventory items. But you can query any properties listed in ItemInstance. If you still have any code question, I'd suggest you check MSDN or Stack Overflow as this is more related to C# language and you may get more detailed help there.

10 |1200

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

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.