Player rating
Get player rating
+1 Requestinfo
Use fetchPlayerRating
to get the player's position in the rating.
You can get the rating position of a player through fetchPlayerRating
. This is a crippled version of fetch
for the player.
- JavaScript
- Unity
const result = await gp.leaderboard.fetchPlayerRating({
// Sorting by fields from left to right
orderBy: ['level', 'gold'],
// DESC sorting – big values first, ASC sorting – small values first
order: 'DESC',
// Include the field list to display in the leaderboard, in addition to orderBy
includeFields: ['rank'],
// Get N nearest players above and below, maximum 10
showNearest: 5,
});
// Response result
const { player, fields, abovePlayers, belowPlayers } = result;
// Player position
player.position;
// Player name
player.name;
// Player avatar
player.avatar;
// Player variables
player.level;
player.gold;
player.myVariable;
//Subscribe to events
private void OnEnable()
{
GP_Leaderboard.OnFetchPlayerRatingSuccess += OnFetchPlayerRatingSuccess;
}
//Unsubscribe from events
private void OnDisable()
{
GP_Leaderboard.OnFetchPlayerRatingSuccess -= OnFetchPlayerRatingSuccess;
}
public void FetchPlayerRating() =>
GP_Leaderboard.FetchPlayerRating(
//Tag for the result processing method
tag = "player12",
// Sorting by fields from left to right
orderBy = "score",
// DESC sorting – big values first, ASC sorting – small values first
order = "DESC"
);
// Response result
private void OnFetchPlayerRatingSuccess(string fetchTag, int position) =>
Debug.Log("LEADERBOARD: " + fetchTag + " PLAYER POSITION: " + position);
Response:
Property | Type | Description |
---|---|---|
player | LeaderboardPlayer | data of my player with position |
abovePlayers | LeaderboardPlayer[] | list of players above my player |
belowPlayers | LeaderboardPlayer[] | list of players below my player |
Get player scoped rating
+1 RequestYou can get the rating position of a player through fetchPlayerRatingScoped
. This is a crippled version of fetchScoped
for the player.
- JavaScript
- Unity
const result = await gp.leaderboard.fetchPlayerRatingScoped({
// leaderboard ID
id: 17,
// leaderboard Tag
tag: 'LEVELS',
// Scope name
variant: 'level_15',
// Add list of player fields to display in table, in addition to table fields
includeFields: ['rank'],
// Get N nearest players above and below, maximum 10
showNearest: 5,
});
// Result
const { player, fields, abovePlayers, belowPlayers } = result;
// Player position
player.position;
// Player name
player.name;
// Player avatar
player.avatar;
// Player variables
player.level;
player.gold;
player.myVariable;
//Subscribe to events
private void OnEnable()
{
GP_LeaderboardScoped.OnFetchPlayerRating += OnFetchPlayerRating;
GP_LeaderboardScoped.OnFetchPlayerRatingError += OnFetchPlayerRatingError;
}
//Unsubscribe from events
private void OnDisable()
{
GP_LeaderboardScoped.OnFetchPlayerRating -= OnFetchPlayerRating;
GP_LeaderboardScoped.OnFetchPlayerRatingError -= OnFetchPlayerRatingError;
}
public void FetchPlayerRating() =>
GP_LeaderboardScoped.FetchPlayerRating(
// leaderboard ID or tag
idOrTag = "LEVELS",
// Scope name
variant = "some_variant",
// Add list of player fields to display in table, in addition to table fields
includeFields = "rank")
);
// Result
private void OnFetchPlayerRating(string fetchTag, int position) =>
Debug.Log("LEADERBOARD SCOPED: " + fetchTag + ": PLAYER POSITION: " + position);
// Fetch rating error
private void OnFetchPlayerRatingError() =>
Debug.Log("LEADERBOARD SCOPED: ON FETCH PLAYER RATING: ERROR");
Response:
Property | Type | Description |
---|---|---|
player | LeaderboardPlayer | data of my player with position |
abovePlayers | LeaderboardPlayer[] | list of players above my player |
belowPlayers | LeaderboardPlayer[] | list of players below my player |
Stay in Touch
Other documents of this chapter available Here. To get started, welcome to the Tutorials chapter.
GamePush Community Telegram
: @gs_community.
For your suggestions e-mail
: [email protected]
We Wish you Success!