transition.to and switching focus

I’m making a game with 2 player  characters, it is a turn based game and one character moves and then the other character moves.

When a character moves, then the board counter moves to put them back in a home position relative to the screen.  It happens with a slight delay so the board is kind of chasing him.  Also, the character moves in a series of transition.to actions, to move in a pattern.  So, when he moves it might fire transition.to 3 to 6 times.

My problem occurs when the game transitions from one character to another: Character 1 has not finished moving when his turn ends and the newTurn() function fires.  On a newTurn, the camera repositions instantly to put character 2 in the home position.  But then character 1 ends his move and the camera returns to him, even though it is no longer his turn.

I’ve tried using onComplete and a timer to fix this problem but so far it doesn’t work as I need it to work

Idealy, what would happen is that the game would just allow character 1 to finish walking before the turn ends.

So, how do I detect when the last transition.to is finished?

I tried saving references to the transition.to objects in a table and then checking to see if the table was empty but I couldn’t get it to work.

My code looked something like this:

currentMap.trans[#currentMap.trans + 1] = transition.to(currentMap, {time = 450, x = newX, y=newY})

and then when the newTurn function fired:

local function centerOnPlayerWhenCueClears()
 print(“centerOnPlayerWhenCueClears begun”)
 local counter = 0
 for i, v in pairs (currentMap.trans) do
  counter = counter + 1
 end
 if counter > 0 then
  timer:performWithDelay(500, centerOnPlayerWhenCueClears)
 else
  P.centerOnPlayer(currentMap.activeCharacter, true)
 end
end