question

John Peterson avatar image
John Peterson asked

How to explicitly retain a specific ItemInstance?

(Title 44B1)

Dear PlayFab Community,

Please bear with me a bit as I try to explain the scenario and what I'm hoping to do, and the behavior that I'm seeing: I have a CatalogItem X that is defined with Stackable and Durable checked. In Game Manager, I grant five of these items to my player. Let's call these ItemInstances A, B, C, D, and E.

I have a CloudScript function that makes a call to server.GetUserInventory(). [Side note: I believe that this would only return one instance of X with a RemainingUses=5, just like it does in the client.] I find my instance of X in the inventory list, and maybe it's ItemInstance B. [I do not know if it always returns the same ItemInstance for every call, but I'm guessing that it does, since the Game Manager seems to "mark" a specific instance as "Active" when they're stacked.]

In this CloudScript function, I eventually call server.ModifyItemUses() to reduce the count by 3, and then I want to update my ItemInstance's CustomData. Here's where I'm running into trouble.

I believe that when I reduce the count by 3, the system is randomly choosing which 3 ItemInstances are getting removed. Such that I will potentially lose the ItemInstance B, for which I was going to update the CustomData. I say this because sometimes I am successful in writing my CustomData, and sometimes I'm getting a failure.

If my hypothesis is correct (and I am in the process of verifying this), is there any way to ensure that a specific ItemInstance can be retained when removing instances?

Thank you in advance for any help anyone can provide!

apisCloudScript
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

·
brendan avatar image
brendan answered

Well first, yes, if an ItemId in the catalog is marked as stackable, then when you add it to a player inventory, that player will have one instance with all additions of that ItemId together (though note that this is not retroactive - if you set the item to be stackable after you add some to the player, the ones already added aren't stackable).

But no, every time you add more of that item, it adds to the same instance. That is, the player will only ever have one instance of the stackable item. That would be the only one that shows up in an inventory query, and so the one to use when updating the custom data.

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.

John Peterson avatar image John Peterson commented ·

Thanks, Brendan! Yeah...I think I was getting an error for a different reason and attributed it to a missing instance. It was very intermittent, however, that led me down the path to thinking that the "Active" instance was randomly getting removed. But I think I've convinced myself that this is no longer the case, and your confirmation sealed the deal. Thanks again!

0 Likes 0 ·

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.