0

In the sandbox environment, I'm having trouble advancing a turnbased match to the next player.

Initial conditions:

  • Player A and Player B on Device A and Device B, respectively.
  • Both logged into the sandbox
  • Both players can see each other's GC status message
  • Player A creates a match and invites player B
  • Player A ends the turn

In my "end turn" function I do the following:

    NSLog(@"size = %ld", updatedMatchData.length);

    //move the current player to the bottom of the list
    NSMutableArray *nextPlayers = (NSMutableArray *)theMatch.participants;
    NSLog(@"%@", [nextPlayers description]);

    GKTurnBasedParticipant *firstGuy = nextPlayers[0];
    [nextPlayers removeObjectAtIndex:0];
    [nextPlayers addObject:firstGuy];

    NSLog(@"------");
    NSLog(@"%@", [nextPlayers description]);

    //send the match to the servers
    //"theMatch" was recorded in turnBasedMatchmakerViewController:didFindMatch

    [theMatch endTurnWithNextParticipants:nextPlayers
                              turnTimeout:GKTurnTimeoutDefault
                                matchData:updatedMatchData
                        completionHandler:^(NSError *error)
    {
        if (error)
        {
            NSLog(@"WTF?");
        }
    }];

That produces the following log output:

size = 26926
(
"<GKTurnBasedParticipant 0x174018630 - playerID:G:1084583147 (local player) status:Active matchOutcome:None lastTurnDate:(null) timeoutDate:(null)>",
"<GKTurnBasedParticipant 0x174018ba0 - playerID:G:12962188 status:Invited matchOutcome:None lastTurnDate:(null) timeoutDate:(null)>"
)
------
(
"<GKTurnBasedParticipant 0x174018ba0 - playerID:G:12962188 status:Invited matchOutcome:None lastTurnDate:(null) timeoutDate:(null)>",
"<GKTurnBasedParticipant 0x174018630 - playerID:G:1084583147 (local player) status:Active matchOutcome:None lastTurnDate:(null) timeoutDate:(null)>"
)

However, player B does not receive an invite or a turn. Player B's game center app shows no active games or turns. Player A's game center continues to show that he still has a turn pending. Each time I restart and re-execute the test, Player A racks up yet another pending turn.

Player A fires player:receivedTurnEventForMatch:didBecomeActive right after I end the turn, but didBecomeActive is set to NO.

So then I changed the timeout to 30 seconds. 30 seconds after playerA ends the turn, playerA fires didBecomeActive (no). PlayerB finally receives an invite prompt. Player B fires didBecomeActive, with a value of YES.

Why does my turn not advance immediately to player B after player A ends the turn? Why does player A seem to have another turn (which then times out and passes over to player B)?

Thunk
  • 4,099
  • 7
  • 28
  • 47
  • Please if you could help me : The log output two times as shown by you. Is it the log result on two different devices by you? – Asim Khan Jul 01 '17 at 13:11
  • It's logging the array contents before and after I modify the array. – Thunk Jul 01 '17 at 16:21
  • In my case this array prints : [ , ] What should I do with this It's not finding the 2nd player for me. – Asim Khan Jul 01 '17 at 18:31
  • You need to open a new question, show your code and explain the problem you're trying to solve. – Thunk Jul 01 '17 at 18:35
  • Sure, then how could I let you know by the time I have opened the question? I've seen a lot of help provided by you here to a number of different question. – Asim Khan Jul 01 '17 at 18:38

1 Answers1

0

Finally solved this. Do not attempt to edit the match object. Don't directly edit the matchData, or any other component of the match. Create a copy, do whatever you need to do to the copy and resubmit the copy.

My attempt to sort the players produced all sorts of erratic results until I created a completely separate participants array and sorted that. Then it worked as advertised.

Thunk
  • 4,099
  • 7
  • 28
  • 47