question

Yoo SeungJi avatar image
Yoo SeungJi asked

Cloud Script UpdatePlayerStatistics

handlers.UpdateTotalRanking = function(args){
    var result = server.GetPlayerProfile( {PlayFabId: currentPlayerId, ProfileConstraints: {ShowLocations: true}} );
    var profile = result.PlayerProfile;
    var gameMode = args.gameMode;
    var totalScore = 0;
    debug.log(profile.Statistics.Count);
    var i = 0;
    for(i;i<profile.Statistics.Count;i++){
        var name = profile.Statistics[i].Name;
        debug.log(name);
        if(name.includes(gameMode)){
            debug.log("TRUE");
            totalScore+=profile.Statistics[i].Value;
        }
    }
    if(totalScore>0){
        log.info("UPDATETOTALSCORE");
        var req = {
            PlayfabId:currentPlayerId,
            Statistics : [{
                StatisticName : "TotalRank"+gameMode,
                Value : totalScore
            }]            
        }
        return server.UpdatePlayerStatistics(req);
    }
        return profile;
};

When user statistics are updated, I want to set the sum of other statistics to total ranking. But this code doesn't work. I want your help.

CloudScriptLeaderboards and Statistics
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.

Yoo SeungJi avatar image Yoo SeungJi commented ·

And how do I display the log here?

0 Likes 0 ·
help.png (23.5 KiB)
Yoo SeungJi avatar image Yoo SeungJi commented ·

There is no ShowStatistics in the code above, but inserting it will not fix the problem.

0 Likes 0 ·

1 Answer

·
Rick Chen avatar image
Rick Chen answered

The result image you provide shows that the “APIRequestsIssued” is 0, meaning it didn’t even execute the 2nd line of your code snippet. Are you sure that you have made the correct request? How does this CloudScript get called? Could you please provide your request body of the API call for us to diagnose?

When I tried your code in my title by calling the ExecuteCloudScript API, I received this error: "ReferenceError: debug is not defined\n at handlers.UpdateTotalRanking (XXXX-main.js:39:5)\n at Object.invokeFunction (Script:116:33)". Please note that the debug.log you used in line 6 is not predefined function, you may use the log.info instead.

10 |1200

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

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.