question

Lesley N avatar image
Lesley N asked

Player Statistic or Title Data daily reset

Hello,

I'm trying to setup an automated daily reset on all players for either Player Statistics or Player Data (Title) but can't seem to get it working correctly.

Do you have any suggestions on the best way to do this?

I've tried using Automation to create a daily cloud script call to reset a specific player statistic but when attempting to run it from the browser it throws an error stating there is no current player.

The idea is to reset WalkingRewards to 0 every single day.

Here's the cloud script code:

handlers.WalkRewards_Reset = function(args, context)
{
    var request = {
        PlayFabId: currentPlayerId, Statistics: [{
                StatisticName: "WalkingRewards",
                Value: 0
            }]
    };
 
    var playerStatResult = server.UpdatePlayerStatistics(request);
}

Any idea what is going wrong here?

Thanks!

Player DataTitle Datadata
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

·
Xiao Zha avatar image
Xiao Zha answered

>>Player Statistics daily reset

Since all statistics defined in PlayFab for players in the game are part of the leaderboard, defining statistics also defines the leaderboard. This means that resetting a specific statistic is resetting a specific leaderboard. And the leaderboard has its own reset method, you can set the reset frequency of the leaderboard to daily in the edit leaderboard page. You can find more information in this documentation: Using resettable statistics and leaderboards - PlayFab | Microsoft Learn.

>>Player Data daily reset

We recommend using Scheduled Tasks to implement this functionality. You can set the Segment option in Edit Scheduled Task to the All Player segment, then add Action with Execute Cloud Script Type and choose the cloud script you want. If you want to execute the cloud script every single day, you can set the SCHEDULE option to Recurring with the time you want.

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

Lesley N avatar image Lesley N commented ·

Yeah so the best bet is Player Data (title), i do have the automation / schedule task setup already as you described for the daily reset, my issue is the actual cloud script code.

For example i'm trying:

handlers.WalkRewards_Reset = function(context)
{


    // set the key
    var setTitleDataRequest = {
        "Key": "WalkRewards",
        "Value": "0"
    };
    
    var setTitleDataResponse = server.SetTitleData(setTitleDataRequest);
    
}

It says the process succeeded, however the title data "WalkRewards" is not being changed to the value indicated (i.e "0")

Thoughts?

0 Likes 0 ·
Lesley N avatar image Lesley N commented ·

I see, the previous method sets the title data globally for that title, not per player, i need the title data to be set on all players.

0 Likes 0 ·
Xiao Zha avatar image Xiao Zha Lesley N commented ·

Yes, you are right.

0 Likes 0 ·
Lesley N avatar image Lesley N Xiao Zha commented ·

Can you provide me with an example on the proper way to update the player title data for all players via cloud script?

0 Likes 0 ·
Show more comments
Show more comments
Xiao Zha avatar image Xiao Zha Lesley N commented ·

Cloud you share the code snippet with us? And did you follow the steps I mentioned above to run the Scheduled Task?

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.