Sign In Register

How can we help you today?

Start a new topic
Answered

Challenge problem - Max players

Hi,

I don't know if this is a problem, but, when my challenge reaches the max players, the state stays at "ISSUED".

How can I catch that a challenge have the reaches the  max players ?


Sorry for my english


Best Answer

Hi Savie,


What you could do is when creating the challenge is set the scriptData of the challenge to hold the maxPlayer count that you have set, then when a player accepts the challenge, check the length of the accepted players array and if it's equal to the maxPlayer number in scriptData, start the challenge. You can use the following to do this.


 

//In CreateChallengeRequest Cloud Code

//get the max players from the request
var maxPlayers = Spark.getData().maxPlayers

//set it to scriptData
Spark.setScriptData("maxPlayers", maxPlayers)


//In CreateChallengeResponse Cloud Code 

//get the maxPlayer number from the scriptData from the request
var maxPlayers = Spark.getScriptData("maxPlayers")

//get the challengeInstanceID from the response
var challengeInstanceId = Spark.getData().challengeInstanceId

//use the challengeinstanceID to set the maxPlayers to the challenges scriptData
var scriptData = Spark.getChallenge(challengeInstanceId).setScriptData("maxPlayers", maxPlayers)

//In the ChallengeAcceptedMessage

//get the challengeID from the message
var challengeInstanceId = Spark.getData().challengeId

//get the amount of accepted players in the challenge
var acceptedPlayers = Spark.getChallenge(challengeInstanceId).getAcceptedPlayerIds().length

//get the maxPlayer count from scriptData
var maxPlayers = Spark.getChallenge(challengeInstanceId).setScriptData("maxPlayers")

//if they're equal, start the challenge.
if (acceptedPlayers = maxPlayers){
Spark.getChallenge(challengeInstanceId).startChallenge();
}



 

Try that and let me know if it suits your needs.


Thanks,

Liam




Hi Team Savie,


When creating your challenge if you set "autoStartJoinedChallengeOnMaxPlayers" to true the challenge will start automatically when a new player joins and maxPlayers is reached. Try that and let us know how you get on.


Thanks,

Liam

Hi,

    It's ok, but it's not the solution I want. I want to go to "ISSUED" at "WAITING" when max players is reach and start the challenge manually.

Answer

Hi Savie,


What you could do is when creating the challenge is set the scriptData of the challenge to hold the maxPlayer count that you have set, then when a player accepts the challenge, check the length of the accepted players array and if it's equal to the maxPlayer number in scriptData, start the challenge. You can use the following to do this.


 

//In CreateChallengeRequest Cloud Code

//get the max players from the request
var maxPlayers = Spark.getData().maxPlayers

//set it to scriptData
Spark.setScriptData("maxPlayers", maxPlayers)


//In CreateChallengeResponse Cloud Code 

//get the maxPlayer number from the scriptData from the request
var maxPlayers = Spark.getScriptData("maxPlayers")

//get the challengeInstanceID from the response
var challengeInstanceId = Spark.getData().challengeInstanceId

//use the challengeinstanceID to set the maxPlayers to the challenges scriptData
var scriptData = Spark.getChallenge(challengeInstanceId).setScriptData("maxPlayers", maxPlayers)

//In the ChallengeAcceptedMessage

//get the challengeID from the message
var challengeInstanceId = Spark.getData().challengeId

//get the amount of accepted players in the challenge
var acceptedPlayers = Spark.getChallenge(challengeInstanceId).getAcceptedPlayerIds().length

//get the maxPlayer count from scriptData
var maxPlayers = Spark.getChallenge(challengeInstanceId).setScriptData("maxPlayers")

//if they're equal, start the challenge.
if (acceptedPlayers = maxPlayers){
Spark.getChallenge(challengeInstanceId).startChallenge();
}



 

Try that and let me know if it suits your needs.


Thanks,

Liam



Hi,

    Thank you. Works well.

Login to post a comment