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 Yoo SeungJi · May 17, 2021 at 05:53 AM · CloudScriptLeaderboards and Statistics

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.

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 Yoo SeungJi · May 17, 2021 at 05:54 AM 0
Share

And how do I display the log here?

help.png (24.0 kB)
avatar image Yoo SeungJi · May 17, 2021 at 06:05 AM 0
Share

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

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by Rick Chen · May 18, 2021 at 08:14 AM

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.

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

    3 People are following this question.

    avatar image avatar image avatar image

    Related Questions

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

    Trigger Cloudscript/Azure function on statistic reset 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

    How Would i make a java script register? 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