question

bomdur88 avatar image
bomdur88 asked

Updating Leaderboard from CloudScript

Hi i'm trying to update the leaderboard from a cloud script the problem is that it register the user correctly but it doesn't update the current score (Its a sum leaderboard)

This is my code from CloudScript

handlers.UpdateLeaderboard = function (args, context)
{
 var AddScore = UpdatePlayerScore(args.Leaderboardname, args.Playerscore);
 
    if (AddScore.leaderboardupdated == true)
       log.info("Statistics updated.");
    else
       log.info("Couldn't update statistics.");
  
    var resultleaderboard = server.GetLeaderboard(
        {
            PlayFabID: currentPlayerId,
            StatisticName : args.Leaderboardname,
            ProfileConstraints: {
                ShowDisplayName : true
            }
        });       
}
 
function UpdatePlayerScore(leaderboardname, score)
{
      var result = server.UpdatePlayerStatistics({
           PlayFabId: currentPlayerId,
           Statistics :[{ StatisticName : leaderboardname, Value : score }]
        });
        
       if (result.Error == null)
           return { leaderboardupdated: true };
       else
           return { leaderboardupdated: false };
}

And this is my current code in Unity

private void UpdatePlayerScore(string leaderboardname, string playerscore)
    {
        var result = new ExecuteCloudScriptRequest
        {
            FunctionName = "UpdateLeaderboard",
            FunctionParameter = new { Leaderboardname = leaderboardname, playerscore },
            GeneratePlayStreamEvent = true
        };


        PlayFabClientAPI.ExecuteCloudScript(result, OnLogginSuccess, OnErrorSuccess);
    }
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.

Rick Chen avatar image Rick Chen ♦ commented ·

I cannot reproduce this issue on Postman, was there any error message when you call the function? Could you check if the playerscore you added was 0?

0 Likes 0 ·
bomdur88 avatar image bomdur88 Rick Chen ♦ commented ·

Hi, i didn't get any errors. The player profile is added to the leaderboard without any problem, but the score is still 0... and no, the player score i added was 100

0 Likes 0 ·

1 Answer

·
bomdur88 avatar image
bomdur88 answered

Found the problem in my unity code i wrote: new{Leaderboardname= leaderboardname, playerscore },
And change it to: new{Leaderboardname= leaderboardname, Playerscore playerscore },

That fixed the problem

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.