Posting Multiple Leaderboard Entries as Player
Introduction
Some of our users have asked if it's possible to post more than one score to a single Leaderboard as a player. The answer is yes, and you can see how it's done with the example given in this tutorial.
We'll cover three stages in setting things up and testing:
- Create an Event with two Attributes.
- Configure your Leaderboard using the Event you've created.
- Test your configuration in the Test Harness.
Creating the Event
First, you'll need to create an Event and add two Attributes:
- The score Attribute is a Number, which will track the Maximum value.
- The character Attribute is a String. The important thing to note here is that we set the Default Aggregation Type to Grouped. This means that the underlying Running Total will use this Attribute to group the other Attributes:
Configuring the Leaderboard
Next, let's configure the Leaderboard:
As you can see from the Fields we've added:
- We're tracking the Maximum score Attribute that we just added to our score_ID Event.
- We've set the Group value for character to ID - this means that each entry, grouped by character, will be posted to a single Leaderboard.
Testing in the Test Harness
We can test the configuration in the Test Harness of our game. Simply authenticate a player and send the requests below. For this example, we're posting scores to the Leaderboard as different characters, which are defined in the character field.
First Request
{
"@class": ".LogEventRequest",
"eventKey": "score_ID",
"score": 50,
"character": "Wizard"
}
Second Requests
{
"@class": ".LogEventRequest",
"eventKey": "score_ID",
"score": 65,
"character": "Warrior"
}
Request to Return Entries
{
"@class": ".LeaderboardsEntriesRequest",
"leaderboards": [
"LB_ID"
]
}
Response
{
"@class": ".LeaderboardsEntriesResponse",
"LB_ID": [
{
"userId": "5c52f106212f9e04f44d0f66",
"score": 65,
"character": "Warrior",
"when": "2019-01-31T13:03Z",
"city": "Dublin",
"country": "IE",
"userName": "TestPlayer_02",
"externalIds": {},
"rank": 1
},
{
"userId": "5c52f106212f9e04f44d0f66",
"score": 50,
"character": "Wizard",
"when": "2019-01-31T13:03Z",
"city": "Dublin",
"country": "IE",
"userName": "TestPlayer_02",
"externalIds": {},
"rank": 2
}
]
}