Question from a developer:
I am currently experiencing an issue with one of my CloudScript functions that is called from the client to unlock a random item from my PlayFab catalog. The function gets a random item using drop tables, verifies that the client has enough currency to purchase the item, and if so deducts the appropriate amount from their balance before granting them the item. A JSON object is returned to the user containing a success flag, the item id, item class, and their new balance.
The issue I am having is that the item class is sometimes null, which should be impossible given that all items in the catalog have a class. I used bulk edit to give the items classes as they were not initially assigned when I entered the items. The value for the item class is coming from the response to the GrantItemsToUser function in the server API.
I cannot figure out what is going on here, if there is some reason why this would happen or there is a bug somewhere. Have you heard of anything like this happening before?
Answer by Brendan · Mar 26, 2017 at 09:36 PM
No, I can't say that what you're seeing has ever been reported by anyone else. So that we can have a look, what is the Title ID in question, what is the handler in your Cloud Script named, what parameters are being passed in when you call it, and what is an example of a response you're getting back with bad or missing values?
Hi Brendan. The Title ID is 8291, handler is named "unlockRandomSkin", and it takes no parameters. An example response when working correctly would be: {"success":true,"itemId":"striped_burgundy_gold_white","itemClass":"Body","balance":4137} and when not {"success":true,"itemId":"striped_lblue_mint_malibu_blue","balance":4237}, notice the missing itemClass property in the JSON in the second example. It appears that this is happening consistently for certain items same items, which all have "Body" classes in my catalog. This seems to be caused by itemClass having a null value in the GrantItemsToUser response, but they should not.
I created a test account in your title (52EFA36C254645EB - feel free to delete it) and ran it through your unlockRandomSkin handler 100 times, and was no table to reproduce this - in all cases, the ItemClass was in the response info. Is there a specific set of steps to your repro?
It appears to happen randomly but it seems be with certain items. Some things that may be noting are:
1) The items did not have an item class when they were created and were bulk edited later.
2) Items were also bulk edited as stackable after they were created and the unlocked skins can be duplicates of items already in the player's inventory.
3) The account I've been testing on may have had some of the unlocked items already in its inventory before the above bulk edits or using the CloudScript function.
I am going to test on a fresh account and see if I can reproduce the problem. Since the CloudScript method seems to be working as intended for you it leaves me to believe the issue is either in my client code or something related to the above points. I will post again with the results on a new account.
Confirming that it is working as intended with the new account, everything makes sense with your explanation. Thanks Brendan!