Class: Leaderboard
Representing a leaderboard. Can be retrieved by calling
LinkGame.getLeaderboardAsync()
.
Methods
getConnectedPlayerEntriesAsync
▸ getConnectedPlayerEntriesAsync(count
, offset
): Promise
<LeaderboardEntry
[]>
Get a list of connected player entries inside the leaderboard based on the count and rank offset specified
Experimental support: please note that this API is subject to breaking change.
Example
// Get top 10 friend entries
leaderboard.getConnectedPlayerEntriesAsync(10, 0)
.then((entries) => {
console.log(entries.length) // 10 if there're >= 10 friend entries
})
Parameters
Name | Type | Description |
---|---|---|
count | number | The number of maximum entries to be retruned |
offset | number | The offset in the leaderborad (from the top) the entries to be returned |
Returns
Promise
<LeaderboardEntry
[]>
Array of entry info
Defined in
getContextID
▸ getContextID(): null
Get ID of the context which the leaderboard belongs to. Since Link
Game Platform doesn't support contextual leaderboard, this method will
only return null
.
Example
LinkGame.getLeaderboardAsync('global_leaderboard')
.then((leaderboard) => {
leaderboard.getContextId() // null
})
Returns
null
Related context ID
Defined in
getEntriesAsync
▸ getEntriesAsync(count
, offset
): Promise
<LeaderboardEntry
[]>
Get a list of entries inside the leaderboard based on the count and rank
offset specified. Since only friends' entries will be returned, this is
effectively the same method as Leaderboard.getConnectedPlayerEntriesAsync()
Experimental support: please note that this API is subject to breaking change.
Example
// Get top 10 entries
leaderboard.getEntriesAsync(10, 0)
.then((entries) => {
console.log(entries.length) // 10 if there're >= 10 entries
})
Parameters
Name | Type | Description |
---|---|---|
count | number | The number of maximum entries to be retruned |
offset | number | The offset in the leaderborad (from the top) the entries to be returned |
Returns
Promise
<LeaderboardEntry
[]>
Array of entry info
Defined in
getEntryCountAsync
▸ getEntryCountAsync(): Promise
<number
>
Get total number of visible entries inside the leaderboard.
Experimental support: please note that this API is subject to breaking change.
Example
LinkGame.getLeaderboardAsync('global_leaderboard')
.then((leaderboard) => {
leaderboard.getEntryCountAsync().then((count) => {
console.log('count: ', count) // count: 2
})
})
Returns
Promise
<number
>
Total number of entries
Defined in
getName
▸ getName(): string
Get the leaderboard's name.
Example
LinkGame.getLeaderboardAsync('global_leaderboard')
.then((leaderboard) => {
leaderboard.getName() // 'global_leaderboard'
})
Returns
string
Leaderboard name
Defined in
getPlayerEntryAsync
▸ getPlayerEntryAsync(): Promise
<null
| LeaderboardEntry
>
Get current player's entry. Returns null
if there isn't one.
Experimental support: please note that this API is subject to breaking change.
Example
leaderboard.getPlayerEntryAsync()
.then((entry) => {
if (!entry) {
console.log('No player entry found')
return
}
entry.getScore() // 100
})
Returns
Promise
<null
| LeaderboardEntry
>
Entry info
Defined in
setScoreAsync
▸ setScoreAsync(score
, extraData?
): Promise
<LeaderboardEntry
>
Submit score to the leaderboard and get the latest entry. A player can only have one entry. If there's already an old entry, it will be only updated to the a better score.
Experimental support: please note that this API is subject to breaking change.
Example
leaderboard.setScoreAsync(100, 'Hello world')
.then((entry) => {
entry.getScore() // 100
})
Parameters
Name | Type | Description |
---|---|---|
score | number | The new score |
extraData? | string | A string payload can be attached to the entry as extra info |
Returns
Promise
<LeaderboardEntry
>
Entry info