Sign In Register

How can we help you today?

Start a new topic

Set the active Player in a turn based challenge


I am making a turn based strategy game and I would like to set the starting player always to the player who is the Challanger. I read here that it is possible to take a "silent turn" if the nextPlayer property is not set as desired.

In Global/ChallengeStartedMessage I do this check

var chal = Spark.getChallenge(Spark.getData().challenge.challengeId);
var challengerId = chal.getChallengerId();
var challengedId = chal.getChallengedPlayerIds()[0];

if(chal.nextPlayer == challengerId)

 As far as I can tell this changes nothing.

Thanks for the Help,


Finally after some long debugging session it works now. Will post the answer here for the case that someone else struggles with the same problem.

It turns out I made severall mistakes.

1. nextPlayer can only be accesed in ChallengeStartedMessage/ChallengeTurnTakenMessage

2. nextPlayer can only be accesd via calling getData()



 3. This was by far the stupidest mistake. Because the game I am working on features 2 players I thought that when nextPlayer was P1 that the player who can now make a move (active player) was P2. Turns out nextPlayer is not the NEXT player more like the ACTIVE player.

Yeah, though this only really helps for 1 vs 1 modes. If we want to be robust to multiple players, we need a loop, but the Spark.getData().challenge.nextPlayer will not update when turns are consumed.

Login to post a comment