Leaderboards - pogamesdk/POGAME-HTML5 GitHub Wiki
Leaderboards
You can display personalized leaderboards on the game page showing the top players' results and the user's position in the ranking.
For the requests below to work, make sure that:
- You've enabled and configured the SDK, and its object is available via the
posdk
variable. - You've created a leaderboard in the Games Console.
Create a Leaderboard
-
Go to the Games Console.
-
Select the game.
-
Open the
Leaderboards
tab and click toAdd
button. -
Fill in the fields:
Field | Description |
---|---|
Leaderboard name | The name that's used for interaction in the SDK. |
Sort order | The order of results in the leaderboard. Acceptable values:- Descending sort: Users with the highest scores will be at the top.- Ascending sort: Users with the lowest scores will be at the top.For example, for a speedrun race, it's best to choose the Ascending sort direction and the time leaderboard type. |
Maximum number of items | This parameter determines how many items is displayed in the leaderboard. |
- Click Submit.
This will create a leaderboard with player IDs shown as cards. You can enable multiple leaderboards for different user groups.
Implementation
Initialization
To initialize the lb object, use the posdk.getLeaderboards()
method:
var lb;
posdk.getLeaderboards()
.then(_lb => lb = _lb);
Leaderboard description
To get a description of a leaderboard by its name, use the getLeaderboardDescription
method.
posdk.getLeaderboards()
.then(lb => lb.getLeaderboardDescription('leaderboard2021'))
.then(res => console.log(res));
Parameter | Description |
---|---|
leaderboardCode | Leaderboard code. Its was generated when uploading your game. |
Response format
{
id: integer,
code: string,
name: string,
description: string
sort: string,
displayCount: integer
}
Parameter | Description |
---|---|
id | Leaderboard ID. |
code | Leaderboard code. |
name | Leaderboard name. |
description | Short description of the leaderboard. |
sort | Sort order: ASC : Scores are sorted in descending order. DESC : Scores are sorted in ascending order. |
displayCount | The maxium items that display on the leaderboard. |
|
New score
To set a new score for a player, use the setLeaderboardScore()
method.
Parameter | Description |
---|---|
leaderboardName | Leaderboard name. |
score | Score. Only the integer type is accepted. The integer must not be a negative number. If the leaderboard type is time, the values must be passed in milliseconds. |
extraData | User description. Optional parameter. |
posdk.getLeaderboards()
.then(lb => {
// Without extraData
lb.setLeaderboardScore('leaderboard2021', 120);
// With extraData
lb.setLeaderboardScore('leaderboard2021', 120, 'My favourite player!');
});
Getting a ranking
To get a user's ranking, use the getLeaderboardPlayerEntry
method:
Parameter | Description |
---|---|
leaderboardName | Leaderboard name. |
posdk.getLeaderboards()
.then(lb => lb.getLeaderboardPlayerEntry('leaderboard2021'))
.then(res => console.log(res));
Response format
{
score: integer,
extraData: string,
rank: integer,
player: {
id: string,
name: string,
avartar: string
}
}
Parameter | Description |
---|---|
score | Score. Only the integer type is accepted. The integer must not be a negative number. |
extraData | User description. Optional parameter. |
rank | Return the rank of current player. |
player | Player data. |
Leaderboard entries
To display users' ratings, use the getLeaderboardEntries
method:
posdk.getLeaderboards()
.then(lb => {
// Using all defaults
lb.getLeaderboardEntries('leaderboard2021')
.then(res => console.log(res));
});
Reponse format
{
leaderboard: {
...
},
userRank: integer,
entries: [
{
score: integer,
extraData: string,
rank: integer,
player: {
id: integer,
name: string,
avatar: string
}
}
]
}
Parameter | Description |
---|---|
leaderboard | Leaderboard description. |
userRank | User's rank. Returns 0 if the user's score isn't in the rankings or if the request is for the top rankings without including the user. |
entries | Requested entries. |
score | Score. Only the integer type is accepted. The integer must not be a negative number. If the leaderboard type is time, the values must be passed in milliseconds. |
extraData | User description. Optional parameter. |
If you are facing an issue or have a question regarding the use of POGAME SDK, please contact support: mailto:[email protected]