Leaderboards not showing all updated scores when sending scores via endMatchInTurnWithMatchData:scores method

242 views Asked by At

I want to implement ELO rating system for a game. It means that after ending a game, I have to calculate increase for winner and decrease for looser from their actual score.

I have leaderboard of type "Most Recent Score" to see just the last sent score. I use loadScoresWithCompletionHandler for loading score, then calculation (now just adding different values) and then endMatchInTurnWithMatchData:scores:achievements:completionHandler: for ending the match and updating the score.

GKTurnBasedParticipant* player1 = [match.participants firstObject];
    GKTurnBasedParticipant* player2 = [match.participants lastObject];
    GKLeaderboard *leaderboardRequest = [[GKLeaderboard alloc] initWithPlayerIDs:@[player1.playerID, player2.playerID]];
    leaderboardRequest.timeScope = GKLeaderboardTimeScopeAllTime;
    leaderboardRequest.identifier = LEADERBOARD_ELO_RATING_ID;

[leaderboardRequest loadScoresWithCompletionHandler:^(NSArray *scores, NSError *error) {
        if(error){
            NSLog(@"%@", error);
            return;
        }
        GKScore *player1Score = [scores firstObject];
        GKScore *player2Score = [scores lastObject];

        float score1 = ((float)player1Score.value) / 1000.0f;
        float score2 = ((float)player2Score.value) / 1000.0f;

        // calculation of new score
        score1 +=10;
        score2 +=1;

        GKScore *player1NewScore = [[GKScore alloc] initWithLeaderboardIdentifier:LEADERBOARD_ELO_RATING_ID forPlayer:player1Score.playerID];
        GKScore *player2NewScore = [[GKScore alloc] initWithLeaderboardIdentifier:LEADERBOARD_ELO_RATING_ID forPlayer:player2Score.playerID];

        player1NewScore.value = (int64_t)(score1 * 1000.0f);
        player2NewScore.value = (int64_t)(score2 * 1000.0f);

        [match endMatchInTurnWithMatchData:[game.board matchData]
                                    scores:@[player1NewScore, player2NewScore]
                              achievements:@[]
                         completionHandler:^(NSError *error) {
                             if(error){// todo handle error
                             }
                         }];
    }];

Getting score and uploading the new score works fine but when I go to see leaderboards (using GKGameCenterViewController or GameCenter app) I can see updated score only by the local player (the participant who has ended the match and sent the final data). But if I do a request by loadScoresWithCompletionHandler method - I can see that scores of both players were updated - but only the local player's is displayed in leaderboardController.

Example:

Match started:
Player A - 10 pts
Player B - 10 pts
Match ended (Player A sent these scores using method endMatchInTurnWithMatchData:scores:achievements:completionHandler:):
Player A - 15 pts
Player B - 8 pts
Match ended - loadScoresWithCompletionHandler result shows scores:
Player A - 15 pts
Player B - 8 pts
Match ended - GKGameCenterViewController or GameCenter app shows scores:
Player A - 15 pts
Player B - 10 pts

Why is this happening, am I doing something wrong? Is it because of using Game Center sandbox? Otherwise how should I exactly update score of both players by endMatchInTurnWithMatchData:scores:achievements:completionHandler:?

1

There are 1 answers

0
Pavel Smejkal On BEST ANSWER

I found out, that it could be probably just because of using Game Center Sandbox.