Sign In Register

How can we help you today?

Start a new topic

Set the active Player in a turn based challenge

Hi,


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)
{
    chal.consumeTurn(challengedId);
}

 As far as I can tell this changes nothing.


Thanks for the Help,

Rene

1 Comment

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()

//WRONG
Spark.getChallenge(chalID).nextPlayer

//RIGHT
Spark.getData().challenge.nextPlayer;

 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.

Login to post a comment