Sign In Register

How can we help you today?

Start a new topic
Answered

Turn Based game challenger play first

im trying to do a turn based game and i want the player who sends the challenge to play first. however sometimes the player who sends the challenge plays first and sometimes the player who gets challenged plays first. Is it my fault or is it random who gets to plays first?


Best Answer

 Hey Nikos,


The challenges are asynchronous, so whichever player submits first starts off the challenge. What you probably want to do is make sure that when the challenger calls the CreateChallengeRequest (like, if you have a popup dialogue where you choose the challenger or something like that), you immediately after the request has come back, submit the challengers score. Therefore, the challenger will always be the first person to play.


Hope that helps,

-Sean




Answer

 Hey Nikos,


The challenges are asynchronous, so whichever player submits first starts off the challenge. What you probably want to do is make sure that when the challenger calls the CreateChallengeRequest (like, if you have a popup dialogue where you choose the challenger or something like that), you immediately after the request has come back, submit the challengers score. Therefore, the challenger will always be the first person to play.


Hope that helps,

-Sean



Is this still the case that which player starts first is selected randomly? 


1 person likes this

I have been using the following code in the ChallengeStartedMessage to see which players turn it is

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


and it definitely seems like it is still random as this has resulted in different players


I am looking for a way to set the player who takes the first turn in a challenge

Any Ideas how to set which player makes the first move instead of it being random?

Hi Jaayden,


You'll have to use SparkChallenges consumeTurn call in Cloud Code if the nextPlayer is not the one you want. 


Thanks,

Liam

Login to post a comment