Updating Multiple Leaderboards with a Single Event and a Custom Running Total
In this tutorial, we'll use a single Event and a custom Running Total to track our score data in different ways:
- Setting Up an Event
- Configuring a Score Leaderboard
- Creating a Custom Running Total
- Configuring a Global Stats Leaderboard
- Testing the Setup
Setting Up an Event
First, we'll set up a myScore Event as follows:
As you can see:
- Our score Attribute's Data Type is set to Number.
- Our attemptCount Attribute's Data Type is also set to Number but it's Default Aggregation Type is set to Count. Giving attemptCount a Default Value means we don't have to include the Attribute when sending the Event. This is perfect for a count Attribute, because all it will do is increment by 1 when we send the Event.
Configuring a Score Leaderboard
Second, we can now create the Leaderboard that simply tracks a user's maximum score. Our Leaderboard set it up is like the one shown below - note that we are selecting the system Running Total that was created automatically for our myScore Event:
Creating a Custom Running Total
To use the data passed in through the myScore Event in a different way, we can create a custom Running Total. Click on the Running Total tab on the Configurator > Leaderboards page and set it up as shown below:
- For the Running Total's Event, we are using the myScore Event we created above.
- For the Running Total's Collectors:
- We use the score Attribute and set the Calculation Type to SUM. This means all of the scores submitted through this Event will be added together in this custom Running Total. Note that the Calculation Type setting on a custom Running Total's Collector overrides the Default Calculation Type set for the Event/Attribute that the Running Total is based on.
- Our attemptCount Attribute is simply set to Count, as it was in the Event.
Configuring a Global Stats Leaderboard
For our GlobalStats_LB Leaderboard, we use our globalStats custom Running Total in the Leaderboard. This means the Leaderboard will display the SUM of all attempts by the player and the Count of all the attempts made by the player:
Testing the Setup
When we've completed all of these set up steps, we can test the myScore Event in the Test Harness.
Authenticate a player in the Test Harness and send the following:
{
"@class": ".LogEventRequest",
"eventKey": "myScore",
"score": 50
}
As you can see, we get a NewHighScoreMessage for both Leaderboards that we created:
{
"@class": ".NewHighScoreMessage",
"leaderboardData": {
"userId": "5c5c31b8031f5bc44d78eacb",
"score": 50,
"when": "2019-02-07T13:25Z",
"city": "Dublin",
"country": "IE",
"userName": "testPlayer",
"externalIds": {}
},
"leaderboardName": "score_LB",
"leaderboardShortCode": "score_LB",
"messageId": "5c5c31c6642c554816793e50",
"notification": true,
"playerId": "5c5c31b8031f5bc44d78eacb",
"rankDetails": {
"globalCount": 1,
"globalTo": 1,
"globalToPercent": 100
},
"summary": "You just moved up the score_LB leaderboard"
}
We've scored 50 on the score_LB Leaderboard.
{
"@class": ".NewHighScoreMessage",
"leaderboardData": {
"userId": "5c5c31b8031f5bc44d78eacb",
"SUM-score": 50,
"COUNT-attemptCount": 1,
"when": "2019-02-07T13:25Z",
"city": "Dublin",
"country": "IE",
"userName": "testPlayer",
"externalIds": {}
},
"leaderboardName": "globalStats_LB",
"leaderboardShortCode": "globalStats_LB",
"messageId": "5c5c31c5642c554816793e02",
"notification": true,
"playerId": "5c5c31b8031f5bc44d78eacb",
"rankDetails": {
"globalCount": 1,
"globalTo": 1,
"globalToPercent": 100
},
"summary": "You just moved up the globalStats_LB leaderboard"
}
We've scored 50 on our first attempt on the globalStats_LB Leaderboard.
Now let's submit another score:
{
"@class": ".LogEventRequest",
"eventKey": "myScore",
"score": 30
}
This score was lower than our last score, so we see no change on the score_LB Leaderboard. This is because we are only tracking the maximum scores submitted by a player on that Leaderboard. However, we'll get a NewHighScoreMessage for our globalStats_LB Leaderboard, because we are tracking the sum of a player's scores on this Leaderboard. As you can see, the SUM-score is now 80 (50 + 30) and COUNT-attemptCount is 2.
{
"@class": ".NewHighScoreMessage",
"leaderboardData": {
"userId": "5c5c31b8031f5bc44d78eacb",
"SUM-score": 80,
"COUNT-attemptCount": 2,
"when": "2019-02-07T13:25Z",
"city": "Dublin",
"country": "IE",
"userName": "testPlayer",
"externalIds": {}
},
"leaderboardName": "globalStats_LB",
"leaderboardShortCode": "globalStats_LB",
"messageId": "5c5c31d0642c55481679477d",
"notification": true,
"playerId": "5c5c31b8031f5bc44d78eacb",
"rankDetails": {
"globalCount": 1,
"globalFrom": 1,
"globalFromPercent": 100,
"globalTo": 1,
"globalToPercent": 100
},
"summary": "You just moved up the globalStats_LB leaderboard"
}