Microsoft Azure PlayFab logo
    • Multiplayer
    • LiveOps
    • Data & Analytics
    • Add-ons
    • For Any Role

      • Engineer
      • Designer
      • Executive
      • Marketer
    • For Any Stage

      • Build
      • Improve
      • Grow
    • For Any Size

      • Solo
      • Indie
      • AAA
  • Runs on PlayFab
  • Pricing
    • Blog
    • Forums
    • Contact us
  • Sign up
  • Sign in
  • Ask a question
  • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Topics
    • Questions
    • Articles
    • Ideas
    • Users
    • Badges
  • Home /
  • General Discussion /
avatar image
Question by bomdur88 · 4 days ago · CloudScriptLeaderboards and Statistics

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);
    }
Comment

People who like this

0 Show 2
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Rick Chen ♦ · 2 days ago 0
Share

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?

avatar image bomdur88 Rick Chen ♦ · 2 days ago 0
Share

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

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by bomdur88 · 2 days ago

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

Comment

People who like this

0 Show 0 · Share
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Navigation

Spaces
  • General Discussion
  • API and SDK Questions
  • Feature Requests
  • PlayStream
  • Bugs
  • Add-on Marketplace
  • LiveOps
  • Follow this Question

    Answers Answers and Comments

    14 People are following this question.

    avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

    Related Questions

    Trigger Cloudscript/Azure function on statistic reset 1 Answer

    Azure Function Update Leaderboard Problem 2 Answers

    Sync PlayFab and Google Play Games / Game Center data 1 Answer

    Is there a way to create Leaderboards and add some players to them via code 1 Answer

    Updating Online / Offline status of player? 1 Answer

    PlayFab

    • Multiplayer
    • LiveOps
    • Data & Analytics
    • Runs on PlayFab
    • Pricing

    Solutions

    • For Any Role

      • Engineer
      • Designer
      • Executive
      • Marketer
    • For Any Stage

      • Build
      • Improve
      • Grow
    • For Any Size

      • Solo
      • Indie
      • AAA

    Engineers

    • Documentation
    • Quickstarts
    • API Reference
    • SDKs
    • Usage Limits

    Resources

    • Forums
    • Contact us
    • Blog
    • Service Health
    • Terms of Service
    • Attribution

    Follow us

    • Facebook
    • Twitter
    • LinkedIn
    • YouTube
    • Sitemap
    • Contact Microsoft
    • Privacy & cookies
    • Terms of use
    • Trademarks
    • Safety & eco
    • About our ads
    • © Microsoft 2020
    • Anonymous
    • Sign in
    • Create
    • Ask a question
    • Create an article
    • Post an idea
    • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Explore
    • Topics
    • Questions
    • Articles
    • Ideas
    • Users
    • Badges