Question

I am planning to use Google Play Game Services to create a multi-player game.

I want to store the following for each user:

  • Matches played
  • Matches won
  • Highest score in a match
  • Total score

I want the leaderboard to display data in descending order for the highest score. Is this possible? Can I submit multi-attribute score and display them in the leadership board?

The format could be somewhat like:

User|Played|Won|Highest|Total

User1| 10 | 8 | 250 | 5000

User2| 20 | 12| 225 | 5400

Was it helpful?

Solution

While possible, it is not without a little bit of development time.

Google has two things that it stores using the Leaderboard that matter for saving a Score:

From Google Developer

public abstract void submitScore (GoogleApiClient apiClient, String leaderboardId, long score, String scoreTag)

Submit a score to a leaderboard for the currently signed in player. The score is ignored if it is worse (as defined by the leaderboard configuration) than a previously submitted score for the same player.

This form of the API is a fire-and-forget form. Use this if you do not need to be notified of the results of submitting the score, though note that the update may not be sent to the server until the next sync.

The meaning of the score value depends on the formatting of the leaderboard established in the developer console. Leaderboards support the following score formats:

Fixed-point: score represents a raw value, and will be formatted based on the number of decimal places configured. A score of 1000 would be formatted as 1000, 100.0, or 10.00 for 0, 1, or 2 decimal places.
Time: score represents an elapsed time in milliseconds. The value will be formatted as an appropriate time value.
Currency: score represents a value in micro units. For example, in USD, a score of 100 would display as $0.0001, while a score of 1000000 would display as $1.00

For more details, please see Leaderboard Concepts.

Required API: API
Required Scopes: SCOPE_GAMES

Parameters
apiClient   The GoogleApiClient to service the call.
leaderboardId   The leaderboard to submit the score to.
score   The raw score value.
scoreTag    Optional metadata about this score. The value may contain no more than 64 URI-safe  characters as defined by section 2.3 of RFC 3986.

So, you can use the long and the String to store the information that you want to save. But, this also means you would not be able to use the Google Leaderboard display methods. Must be all custom built by you.

For example, in storing/retrieving your scores, I would break up the long into sections. Long.MAX_VALUE = 9223372036854775807, so you can split that up into Score/Won/Played (that way your score value still sorts the players correctly via Google's retrieval system) and perhaps store Highest score in the String. (with whatever else you may want)

So when you retrieve scores the raw scores and the scoreTag might be stored as:

User2 54000001200020   "225"
User1 50000000800010   "250"

Now if your Highest Is actually how you want scores sorted (vice total like I show here), then stick that at the front.

Then, just need to break out each score part, and format for display...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top