question

OsmanSaleem avatar image
OsmanSaleem asked

How to make a Get LeaderBoard Request using JavaSript (PlayCanvas)

Hi, hope you are doing well.

I have recently switched to playcanvas from unity to make a Game for Web and they support playfab but I am having it a bit rough to make a simple leader board; coming from C# to Js environment .Upon searching many requests, i have found that there isnt a lot of material related to PlayCanvas x PlayFab, therefore i am writing my query here and hope it get answered for future purposes. (It would be wonderful if i get any helpful/side material related to Playcanvas and Playfab).

So coming to my question, i am having trouble in getting the leaderboard from the playfab player database. For updating statistics, the solution has been completed where i used the following code to update my score and it works like a charm.

PlayFabManager.prototype.UpdateStats=function(score){
var updateStatsRequest ={
Statistics:[{StatisticName:"UserScores",Value: score }]
};
PlayFabClientSDK.UpdatePlayerStatistics(updateStatsRequest, updateStatsCallback);
};

But i want this leaderboard entry to be displayed inside my game. Any solution how this may be possible.
Thank you, hope you have a good day.

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.

Made Wang avatar image
Made Wang answered

I'm not familiar with PlayCanvas, but I can provide you the code to call GetLeaderboard in JS, you can refer and try to modify it.

Also, PlayFab has no official documentation for PlayCanvas, but you can refer to JavaScript quickstart for Native and Phaser - PlayFab | Microsoft Docs to understand how to call PlayFab’s API in JS.

function GetLeaderboard(){
    var getLeaderboardRequest = {
        StartPosition: 0,
        StatisticName: "UserScores"
    };
    PlayFabClientSDK.GetLeaderboard(getLeaderboardRequest, getLeaderboardCallback);
}
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.

OsmanSaleem avatar image OsmanSaleem commented ·

Thank you for sparing some time brother. I will look into it.

0 Likes 0 ·
OsmanSaleem avatar image
OsmanSaleem answered

Ps. By displayed in my game i meant how can i get access to the contents of the data actually. I know that it can be shown in multiple ways e.g. specifying a text component etc.Thank you.

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.