1
\$\begingroup\$

I want to implement a Google Leaderboard in my game. The score I will send to the leaderboard is a single long number.

Now I want to make sure that the user's progress won't get lost when reinstalling the app, buying a new mobile, etc.. So I can't store that single long in the Shared Preferences. And I also can't get the user's score back from the leaderboard, since it only supports sending scores (right?).

So I was thinking of implementing a Google SaveGame for that.

What would be the app flow for that?

Thanks in advance!

\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

You can get the score back from the leaderboard.

Using the loadCurrentPlayerLeaderboardScore API call you can get a LeaderboardScore object back that contains the long representation of the score.

You could call it like this;

private void loadScore(String leaderboardId) {
    Games.Leaderboards.loadCurrentPlayerLeaderboardScore(getApiClient(), getString(leaderboardId), LeaderboardVariant.TIME_SPAN_ALL_TIME, LeaderboardVariant.COLLECTION_PUBLIC).setResultCallback(new ResultCallback<Leaderboards.LoadPlayerScoreResult>() {
        @Override
        public void onResult(final Leaderboards.LoadPlayerScoreResult result) {
            if (result != null && result.getStatus().getStatusCode() == GamesStatusCodes.STATUS_OK) {
                if (result.getScore() != null) {
                    // At this point you have a score
                    long score = result.getScore().getRawScore();
                }
            }
        });
}
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .