Sign In Register

How can we help you today?

Start a new topic

How to ensure that the challenged player always takes the next turn after a challenge is created

I have noticed that after a challenge is created the nextPlayer is randomly chosen. I have been looking for a way to explicitly set who the nextPlayer is when creating a challenge but havent found a way so far. As a work-a-round I am trying to conditionally consume the nextPlayers turn in ChallengeStartedMessage if the nextPlayer ends up being the challenger.


var nextPlayer = Spark.getData().challenge.nextPlayer;

var challengerId = challenge.getChallengerId();

if (challengerId == nextPlayer) {

    SparkChallenge.consumeTurn(nextPlayer);

}


However this still doesnt product consistent results as sometimes its still the challenger's turn after the challenge is created.


Hi Jaayden,


Your code there looks fine. With that in place it should always be the challenged players turn. How many players are in this challenge ? Currently there is no way to set the turns of a challenge manually.


Thanks,

Liam

There are 2 players in the challenge.


What I did discover is that SparkChallenge.consumeTurn(nextPlayer); 

does not work. When debugging in the test harness, when trying to step over this line of code the debugger freezes and eventually just exits the ChallengeStartedMessage code.


if I change this line to:

var result = challenge.consumeTurn(nextPlayer);


then it works as expected. This was confusing for me because this other forum post provides an answer to use this code, SparkChallenge.consumeTurn(nextPlayer);


https://support.gamesparks.net/support/discussions/topics/1000042171


Another question I have is if the debugger stops working because of a code error, is there any way to see what the actual error is that caused the debugger to stop working?

Login to post a comment