question

Grant McNamara avatar image
Grant McNamara asked

How would i add a leaderboard using javascript?

I'm using a site called play canvas to make a game and they support playfab but I don't know how to make a leaderboard with it.

Leaderboards and Statistics
10 |1200

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

Gosen Gao avatar image
Gosen Gao answered

You could call API UpdatePlayerStatistics in your game and PlayFab will create Leaderboard based on the statistics you upload. Please note that PlayFab doesn’t allow client to post player statistics, you need to navigate to [GameManager]->[TitleSettings]->[API Features] and enable [Allow client to post player statistics]. Because in the common scenario, permitting clients to post statistics will cause abusive use as it changes the ranks for each player.

The code should be something like this.

function UpdatePlayerStatistics(){
    PlayFab.settings.titleId = "xxx";
    var request = {
        Statistics: [
            {
                StatisticName: "xx",
                Value: 10
            }
        ] 
    };
    PlayFabClientSDK.UpdatePlayerStatistics(request, Callback);
}
var Callback = function (result, error){
    // context
}
10 |1200

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

Grant McNamara avatar image
Grant McNamara answered

could you dumb it down a little please im kind of new to this stuff.

where would i use this and how would i configure it.

10 |1200

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

Grant McNamara avatar image
Grant McNamara answered

also how would i display the leaderboard

https://playcanvas.com/editor/scene/1229247

1 comment
10 |1200

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

Gosen Gao avatar image Gosen Gao commented ·

>>where would i use this and how would i configure it.

First, you need to import PlayFab JavaScript SDK into your project. Then you can implement the code in a script. Please follow the official document - https://docs.microsoft.com/en-us/gaming/playfab/personas/developer to learn more about how to work with PlayFab.

>>also how would i display the leaderboard

After you update a player’s statistics, you can call API GetLeaderboard to get the corresponding leaderboard.

Please feel free to let me know if you have any other questions.

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.