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
C
Customer Support
said
over 6 years ago
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();
}
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
T
Team Savie
said
over 6 years ago
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.
Customer Support
said
over 6 years ago
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();
}
Team Savie
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
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.
Try that and let me know if it suits your needs.
Thanks,
Liam
- Oldest First
- Popular
- Newest First
Sorted by Oldest FirstCustomer Support
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
Team Savie
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.
Customer Support
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.
Try that and let me know if it suits your needs.
Thanks,
Liam
Team Savie
Hi,
Thank you. Works well.
-
Documentation Notes
-
Design issues with user events
-
Using NoSQL
-
Runtime Collections vs Metadata Collections
-
Anonymous authentication from browser app
-
Modules
-
Movement With Unity
-
Problem with url parameters for downloadables
-
Querying NoSql GameSparks database
-
Challenge accesType
See all 2487 topics