question

kevin avatar image
kevin asked

Error when updating multiple stats from CloudScript: The StatisticName field is required

Hello,

I'm seeing an error when trying to update multiple player stats from CloudScript. Is there a limit on how many stats that can be updated fromCloudScript? I'm updating 13 stats on a player, and they look something like the following:

handlers.UpdateUserStatData = function (args) { server.UpdatePlayerStatistics({ "Statistics": [ { "StatisticName": "totalAbilityUses", "Value" : args.totalAbilityUses },

..etc

I see the following error when trying to make the request:

"apiError": {
                        "code": 400,
                        "status": "BadRequest",
                        "error": "InvalidParams",
                        "errorCode": 1000,
                        "errorMessage": "Invalid input parameters",
                        "errorHash": null,
                        "errorDetails": {
                            "StatisticName": [
                                "The StatisticName field is required."
                            ]
                        }
                    }

"TitleId": "FB03",

    "EventId": "86138e9fdf934cb0904cc2c33b052b07",
    "EntityId": "52FE51A33D5CFEFC",

I am seeing a success in updating just one or two stats. But when I get past updating 4 or 5 stats at once, sometimes it works and sometimes it errors out.

Thanks!

Kevin

10 |1200

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

1807605288 avatar image
1807605288 answered

This has come up again, and the actual answer is hidden in the comments, so I'm bringing the "correct" answer up to the top of the thread:

The value of a statistic must be an integer. Cloud Script, and several SDKs use a "number" type, which is actually an 8-byte floating point. If the "Value" field is set to something that doesn't parse correctly into a "uint" type on our C# server, then the error result is presented as:

"The StatisticName field is required" - obviously this is incorrect, and we've filed a bug to have this resolved, but in the meantime, just fix your inputs, and ensure you're rounding your values to the nearest uint-value before sending them to PlayFab.

2 comments
10 |1200

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

Tamer Nasser avatar image Tamer Nasser commented ·

Still not fixed...

0 Likes 0 ·
Andy Metcalfe avatar image Andy Metcalfe commented ·

Thank you very much, after much hair pulling this has saved the day! @Brendan this error message needs fixing!

0 Likes 0 ·
brendan avatar image
brendan answered

Can you give us the Title ID and Revision number of the script in question, so that we can review? The UpdatePlayerStatistics call should work fine for what you're trying to do.

12 comments
10 |1200

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

kevin avatar image kevin commented ·

Yes - it is title id: FB03, revision 58, UpdateUserStatData handler

0 Likes 0 ·
brendan avatar image brendan kevin commented ·

I'm not seeing anything wrong with this, and I copied the handler to my own test title and it works fine there. Do you mind if I create a player in your title to test this specifically there? To be clear, a) yes, you shouldn't be writing to more than 25 stats at a time, but you're not over that limit, and b) that error should only occur if the StatisticName were missing from one or more of the StatisticUpdate array elements.

0 Likes 0 ·
kevin avatar image kevin brendan commented ·

Sure, feel free to create a player for FB03, it's our dev title. But yes we have seen it work with a few stats but after we start sending in the whole batch, the performance is intermittent. One time it had worked but the other times it fails.

0 Likes 0 ·
Show more comments
fiveampsoftware avatar image fiveampsoftware commented ·

Hi Brendan, following up on this. We are still seeing a few issues regarding multiple stats. Please see our title's latest API errors - title id A9F. Thanks

0 Likes 0 ·
brendan avatar image brendan fiveampsoftware commented ·

It looks like you've got a bug where the call is being made to update the all stats twice in a row. Have a look at this player's history, for instance: https://developer.playfab.com/en-us/A9F/players/CCDE57EA799ED6E8/event-history. So it looks like two back-to-back calls are being made to update all the stats, which is causing a conflict during the update. Can you check the title code for this?

0 Likes 0 ·
fiveampsoftware avatar image fiveampsoftware brendan commented ·

Hi Brendan, checked this and saw the conflict error - thanks! We'll make some changes so this doesn't happen. But now does that also affect the "invalidparams" error we've seen? Or is that a different issue?

0 Likes 0 ·
Show more comments
fiveampsoftware avatar image fiveampsoftware commented ·

Hi Brendan, can you take a look at the following? https://developer.playfab.com/en-us/A9F/players/7AD927D28FD54822/event-history?query=ZXZlbnREYXRhLmV2ZW50TmFtZSUzQSdwbGF5ZXJfZXhlY3V0ZWRfY2xvdWRzY3JpcHQn

From what I see here is that the player's stats are empty and yet the cloud script has failed with the error The StatisticName field is required. The other events in the history change show that the cloud script was only called once.

This is with a new release that doesn't make the call multiple times too. Very intresting and hard to repro as well.

0 Likes 0 ·
fiveampsoftware avatar image fiveampsoftware fiveampsoftware commented ·

Hi Brendan, it looks like I found the issue. We are storing non int32 values in the stat keys https://api.playfab.com/Documentation/Server/datatype/PlayFab.Server.Models/PlayFab.Server.Models.StatisticUpdate . Will fix this on the client side - thanks!

0 Likes 0 ·
brendan avatar image brendan fiveampsoftware commented ·

Yes, that's what I was just about to point out - that you've encountered a bug we weren't aware of in the error reporting. You are correct that only int32 values are valid for stats. The fractional number was somehow tripping up the logic, causing it to erroneously return that the StatisticName was missing. I'll file a bug to get that fixed.

0 Likes 0 ·
Show more comments

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.