Accessing Leaderboard Data with Cloud Code
There are many scenarios where you might want to access Leaderboard data. For example, you might want to:
- Determine the position of given player within a Leaderboard.
- Get the id of a player who is at a given position on the Leaderboard.
You can implement these two features using the Cloud Code SparkRequests API. This API allows requests to be sent either as the current player or as any other player within your game.
To find the rank of a given player, you can use a LeaderboardDataRequest, which will return the data associated with the player:
var request = new SparkRequests.LeaderboardDataRequest(); request.entryCount = 1; request.leaderboardShortCode = "leaderboardSC"; var response = request.Send();
Now you'll have the GameSparks response stored in your response variable as a JSON object.