EmilyJ
EmilyJ

Reputation: 892

GKTurnBasedMatch does not advance to next player

So my match has two players. When the player 1, creates a new match, I use endTurnWithNextParticipants method and supply the nextParticipants with GKTurnBasedMatch's participants array property which has two participants.

But on the player 1 device, it keeps saying that it is your turn. And player 2's device, it says "their turn".

- (void)endTurnWithNextParticipants:(NSArray<GKTurnBasedParticipant *> *)nextParticipants
                        turnTimeout:(NSTimeInterval)timeout
                          matchData:(NSData *)matchData
                  completionHandler:(void (^)(NSError *error))completionHandler

Any suggestions?

Edit:

Here is how I used endTurnWithNextParticipants. currentTurnBasedMatch is an instance of GKTurnBasedMatch. I did verify that instance does contain two participants (player 1 and 2) correctly. And the completion does not have any error.

[self.currentTurnBasedMatch endTurnWithNextParticipants:self.currentTurnBasedMatch.participants turnTimeout:GKTurnTimeoutDefault matchData:data completionHandler:^(NSError * _Nullable error) {
    MyNSLogSys2O(@"completion error:", error);  //default 1 week timeout
}];

Upvotes: 1

Views: 125

Answers (1)

Thunk
Thunk

Reputation: 4177

I see two problems here:

First and foremost, you're re-using the array that's already stored in a match. That's a non-mutable array and simply passing it back again to endTurnWithNextParticipants results in all sorts of weird behavior that might work sometimes, but causes really weird problems most of the time. I learned this the hard way, myself: GameCenter: endTurnWithNextParticipants not advancing. Create an entirely new array and copy the participants into it. Pass that new array into endTurnWithNextParticipants

Second, I don't see you trying to adjust the order of the participants in the array to indicate you want to change to the next player. (it wouldn't have worked right anyway by re-using the immutable array in the match, but it still has to be done) If you only have two players, you can use the method I used in the link above. If you have more than two players, you need to do something like the accepted answer at this question: Game Center's Auto-match and endTurnWithNextParticipants

Upvotes: 2

Related Questions