Module: leaderboard
PLATFORM NOTE: Facebook does not support global leaderboards, so all leaderboard names will have the current contextID appended to them automatically. You must be in a context to use the Leaderboard API on Facebook, otherwise the calls will reject.
Table of contents
Functions
- getConnectedPlayersEntriesAsync
- getEntriesAsync
- getEntryCountAsync
- getLeaderboardAsync
- getPlayerEntryAsync
- sendEntryAsync
Functions
getConnectedPlayersEntriesAsync
▸ getConnectedPlayersEntriesAsync(name
, count
, offset
): Promise
<LeaderboardEntry
[]>
Retrieves the leaderboard score entries of the current player's connected players (including the current player), ordered by local rank within the set of connected players.
Example
Wortal.leaderboard.getConnectedPlayersEntriesAsync('global')
.then(entries => console.log(entries));
Parameters
Name | Type | Description |
---|---|---|
name |
string |
The name of the leaderboard. |
count |
number |
The number of entries to attempt to fetch from the leaderboard. Defaults to 10 if not specified. Currently, up to a maximum of 100 entries may be fetched per query. |
offset |
number |
The offset from the set of ordered connected player score entries to fetch from. |
Returns
Promise
<LeaderboardEntry
[]>
Promise that resolves with the leaderboard entries that match the query.
Throws
- NOT_SUPPORTED
- INVALID_PARAM
- NETWORK_FAILURE
- RATE_LIMITED
getEntriesAsync
▸ getEntriesAsync(name
, count
, offset?
): Promise
<LeaderboardEntry
[]>
Retrieves a set of leaderboard entries, ordered by score ranking in the leaderboard.
Example
Parameters
Name | Type | Description |
---|---|---|
name |
string |
The name of the leaderboard. |
count |
number |
The number of entries to attempt to fetch from the leaderboard. Defaults to 10 if not specified. Currently, up to a maximum of 100 entries may be fetched per query. |
offset? |
number |
The offset from the top of the leaderboard that entries will be fetched from. Default is 0. |
Returns
Promise
<LeaderboardEntry
[]>
Promise that resolves with the leaderboard entries that match the query.
Throws
- NOT_SUPPORTED
- INVALID_PARAM
- NETWORK_FAILURE
- RATE_LIMITED
getEntryCountAsync
▸ getEntryCountAsync(name
): Promise
<number
>
Gets the total number of entries in the leaderboard.
Example
Parameters
Name | Type | Description |
---|---|---|
name |
string |
The name of the leaderboard. |
Returns
Promise
<number
>
Promise that resolves with the number of entries.
Throws
- NOT_SUPPORTED
- INVALID_PARAM
- NETWORK_FAILURE
- RATE_LIMITED
getLeaderboardAsync
▸ getLeaderboardAsync(name
): Promise
<Leaderboard
>
Fetch a specific leaderboard belonging to this game.
Example
Wortal.leaderboard.getLeaderboardAsync('global')
.then(leaderboard => console.log(leaderboard.name()));
Parameters
Name | Type | Description |
---|---|---|
name |
string |
The name of the leaderboard. Each leaderboard for a game must have its own distinct name. |
Returns
Promise
<Leaderboard
>
Promise that resolves with the matching leaderboard, rejecting if one is not found.
Throws
- NOT_SUPPORTED
- LEADERBOARD_NOT_FOUND
- NETWORK_FAILURE
- CLIENT_UNSUPPORTED_OPERATION
- INVALID_OPERATION
- INVALID_PARAM
getPlayerEntryAsync
▸ getPlayerEntryAsync(name
): Promise
<LeaderboardEntry
>
Retrieves the leaderboard's entry for the current player, or null if the player has not set one yet.
Example
Parameters
Name | Type | Description |
---|---|---|
name |
string |
The name of the leaderboard. |
Returns
Promise
<LeaderboardEntry
>
Promise that resolves with the current leaderboard entry for the player.
Throws
- NOT_SUPPORTED
- INVALID_PARAM
- INVALID_OPERATION
- NETWORK_FAILURE
- RATE_LIMITED
sendEntryAsync
▸ sendEntryAsync(name
, score
, details?
): Promise
<LeaderboardEntry
>
Updates the player's score. If the player has an existing score, the old score will only be replaced if the new score is better than it. NOTE: If the leaderboard is associated with a specific context, the game must be in that context to set a score for the player.
Example
Parameters
Name | Type | Description |
---|---|---|
name |
string |
The name of the leaderboard. |
score |
number |
Score for the entry. Must be a 64-bit integer number. |
details? |
string |
Optional metadata to associate with the stored score. Must be less than 2KB in size. |
Returns
Promise
<LeaderboardEntry
>
Promise that resolves with the current leaderboard entry for the player after the update.
Throws
- NOT_SUPPORTED
- LEADERBOARD_WRONG_CONTEXT
- NETWORK_FAILURE
- CLIENT_UNSUPPORTED_OPERATION
- INVALID_PARAM
- INVALID_OPERATION
- RATE_LIMITED