Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to increment player score in leaderboards on Android Google Play Service?

I read all documentation about leaderboards in Google Play Services and it seems that when I call the submitScore function of GameClient the service take account of the highest score submitted only. E.g.:

1st call:

gamesclient.submitScore( 100 );

Now player score is 100

2nd call:

gamesclient.submitScore( 150 );

Now player score is 150

3rd call:

gamesclient.submitScore( 100 );

player score still remains 150. Submitted value isn't greater than last so it is ignored.

Is there a simple way to retrieve last player score, sum the new score and submit the total for create an incremental score leaderboard ? Something like

int old_score = ...GET LAST PLAYER SCORE...
int new_score = old_score + current_game_score;
gamesclient.submitScore( new_score );
like image 494
danny brown Avatar asked Jan 20 '14 11:01

danny brown


1 Answers

Didn't test it so far, but i think thats the way to go:

    PendingResult<Leaderboards.LoadPlayerScoreResult> result = Games.Leaderboards.loadCurrentPlayerLeaderboardScore(gameHelper.getApiClient(),"LEADERBOARD_ID",LeaderboardVariant.TIME_SPAN_ALL_TIME, LeaderboardVariant.COLLECTION_PUBLIC);
    result.setResultCallback(new ResultCallback<Leaderboards.LoadPlayerScoreResult>() {
        @Override
        public void onResult(Leaderboards.LoadPlayerScoreResult loadPlayerScoreResult) {
            Games.Leaderboards.submitScore(gameHelper.getApiClient(), "LEADERBOARD_ID",loadPlayerScoreResult.getScore().getRawScore()+ score);
        }
like image 86
Kedu Avatar answered Sep 30 '22 22:09

Kedu