I am trying to end my 2 player turn-based game after the current player quits with this code:
NSUInteger currentIndex = [match.participants indexOfObject:match.currentParticipant];
GKTurnBasedParticipant *curr = match.currentParticipant;
GKTurnBasedParticipant *next = [match.participants objectAtIndex:(currentIndex + 1)%[match.participants count]];
[match participantQuitInTurnWithOutcome:GKTurnBasedMatchOutcomeQuit
nextParticipants:@[next]
turnTimeout:MAXFLOAT
matchData:matchData
completionHandler:^(NSError *error) {
if (error) {
NSLog(@"%@", error);
}
[curr setMatchOutcome:GKTurnBasedMatchOutcomeQuit];
[next setMatchOutcome:GKTurnBasedMatchOutcomeWon];
[match endMatchInTurnWithMatchData:matchData
completionHandler:nil
However I'm getting the error: Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'invalid matchOutcome for participant'
Any ideas why?
Re-update your match by calling the class func "loadMatchWithID:"
then call "endMatchInTurnWithMatchData:" after setting the matchOutcome of each participants.
You might be getting this error "reason: 'invalid matchOutcome for participant'" because your data is out of sync.
alternative ------------> Or you could just use "endMatchInTurnWithMatchData:" since it will result in same output, just make sure to update any necessary data needed.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.