question

Dylan Hunt avatar image
Dylan Hunt asked

Need help updating stats from cloud script to 1++ existing vals

I'm a bit confused about how "version" works for:

https://api.playfab.com/documentation/Server/datatype/PlayFab.Server.Models/PlayFab.Server.Models.StatisticUpdate

If I have "wins" statistic and I want to +1 the value, if I include a version, it ADDS to that? How do I know what version was the last one?

Essentially, do I need to make a REQUEST to get stats before I update them, if I'm incrementing previous stats?

CloudScript
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

No, if you want to set up a statistic to increment by the amount you specify in the UpdatePlayerStatistics call, you should set the statistic to the "Sum" aggregation method. Using "Sum" means that any amount submitted for the statistic will be added to the current value. Version, in the context of statistics, refers specifically to resetting the statistic for all players. So, if you set a statistic to reset on a regular interval, you'll see that the version increments on each reset.

4 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.

Dylan Hunt avatar image Dylan Hunt commented ·

(edited) Awesome, thanks! I looked at an example for Mongo @

https://docs.mongodb.com/manual/reference/operator/aggregation/sum/

So for example, would these work:

var updatePlayerStatsReq = 
{
    "PlayFabId": currentPlayerId,
    "Statistics": [            {                
        "StatisticName": "someCounter",
        "Version": 1,
        "Value": { $sum: 1 } // This should someCounter++
},
...,
"Value": { $sum: 25 } // someValue + 25
0 Likes 0 ·
brendan avatar image brendan Dylan Hunt commented ·

No, Sum aggregation is just a setting on the leaderboard - have a look at the leaderboard's settings in your title (go to the leaderboards tab, click to view the leaderboard itself, then click to edit it). All you do is pass the value in as you would for any leaderboard call - just

"Value": 1

(or whatever value you need to add), and if your leaderboard is set to Sum, it'll add that to the current value.

1 Like 1 ·
Dylan Hunt avatar image Dylan Hunt brendan commented ·

OH!!! So for any stat that requires a max, lowest, or sum, i shouldnt call updatestats -- i should call updateLeaderboard? I think i get it ~

EDIT: Oh, there is no updateLeaderboard call -- so I just update stats like normal and leaderboard will pick it up automatically if it's set in dash?

Bonus question - I can't seem to delete a leaderboard entry i must have made like 6 months ago testing it. No easy way to delete it, I'm going to guess?

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.