brainCloud leaderboards are pretty simple. They record and sort the leaderboard entries based on the player's score
, with a secondary sort on the time that the leaderboard entry was created/updated. (i.e. Newer entries of the same score value rank higher than older ones...) <- This is so that players who are actively playing your game *now* get more satisfaction.
But maybe your use case is more complicated - and there is a different secondary criteria that you'd like considered - like the time that it took to complete the round. e.g. Players that get the same score with a shorter round time should rank higher than players with the same score that took longer.
This can be accommodated by using a structured, encoded score - together with optional "extra data" field that leaderboard entries support.
I can structure my score into components like this:
structured score = base component + timing component
Here is how we calculate the components:
base component =
score
xmultiplier
timing component = (600 x 10) -
timeInTenthsOfSecond
You should pick a multiplier for the base component that moves the scores outside of the range being used by the timing component. A safe multiplier would be anything higher than 6000
(the maximum timing component score). Using a factor of 10 is more readable though - so we will use 10,000
.
Let's try a simple example. Joe and Tracy each get score of 125,000 points - but Joe completed the 2 minutes, while Tracy managed to complete the round in 1 minute, 59.5 seconds!
Here is what their scores will look like:
Joe's structured score = (125,000 x 10,000) + (6000 - 1200) = 1,250,004,800
Tracy's structured score = (125,000 x 10,000) + (6000 - 1195) = 1,250,004,805
Note that when encoded this way, Tracy's score is 5 points higher - which is what we want!
The final step to your solution is to include the score component information as the data
parameter in the PostScoresToLeaderboard()
API call.
That way, when you game is displaying the scores, it can display the player's score (and potentially their completion time) as you'd expect in the leaderboard.
Hope that helps!