GameKit turn timeout

275 Views Asked by At

GameKit allow us to end a turn with a timeout for the next participant in the match. However, I couldn't find a way to set a timeout for the first participant for its first move. Is there anyway to do that?

EDIT It started to make sense to me why Apple would leave this out from GameKit. When you just join a GKTurnBasedMatch you will always be in turn so there's no need for a timeout considering that it was added to avoid frustration on players while waiting too long for their turn. The thing is that my use case for a timeout is different. I'm designing a tournament and a timeout means that you lost the match, no matter it's the first turn or not. So I always need to have the ability to timeout the current turn. I'm afraid I'll need to implement this on the server which just sucks.

2

There are 2 best solutions below

0
On

Like you point out, as player1 on turn1, there aren't any other players yet, so I suspect that's why GC doesn't give us an interface to set the timeout for player1.

How about setting an NSTimer to the desired timeout, and then ending the turn when it fires?

If you're looking at a long timeout, say a few days, where the user might leave and then rejoin after the timeout, you could calculate the desired deadline by adding the timeout interval to the match start time, and store that in NSUserDefaults. On each game startup, check if the deadline has passed, and end the turn when appropriate.

0
On

Might be a little late on this one, but Game Center TBM timeouts don't work like that.

When you call endTurnWithNextParticipants you must provide a list of players that will receive the turn if the previous one times out. If you want a player to lose the game when he/she times out, you must implement this e.g. on the client of the next player that receives the turn, Apple serves won't do this for you.

Based on what you're aiming for, I think the best implementation would be to check for the time the latest turn was played, or the match creation time in case it's the first turn, compare it to the current system date and time and programmatically end the match if time is over.