I have created a 2 player turn based game. I want each player to have 24 hours to make their turn. If they don´t meet this time limit, I want to end the game.
.
I have tried using a NSTimer, with this the function below as the selector.
func timerCalled() {
for part in currentMatch!.participants! {
(part ).matchOutcome = .Tied
}
currentMatch?.endMatchInTurnWithMatchData(data!, scores: nil, achievements: nil, completionHandler: { (error) -> Void in
if error != nil {
print(error)
}
self.statusLabel?.text = "Game has ended"
})
}
My game, however, crashes when this function is run, with this printed to the console:"The requested operation could not be completed because the session is in an invalid state". It crashes because I start the timer after the player has made his turn, so it is no longer his turn when "he" ends the game. I am sure it will work if I get the current player to end the game when the time is up, but how/when do I start the timer? When player 1 has made his turn, I have to start the timer with Player 2. How do I do this?