I am making a turn based last man standing game which means that I will have to skip turns of the players who are no longer part of challenge. How can I skip turn at server side ?
Thanks
Abhishek Bansal
Best Answer
T
Tech Support
said
over 8 years ago
Hi Abhishek
If you call SparkChallenge.consumeTurn(String playerId) the turn token will be moved to the next player.
You could use this along with your own logic to skip the players who are no longer "standing"
If you call SparkChallenge.consumeTurn(String playerId) the turn token will be moved to the next player.
You could use this along with your own logic to skip the players who are no longer "standing"
Hope thats useful
Gabriel
A
Abhishek Bansal
said
over 8 years ago
Hi Gabriel,
Will try this !
Thanks
A
Abhishek Bansal
said
over 8 years ago
Hi Gabriel !
I am confused with where to call this ?
in challenge events ?
How can I know the who is the next turn.. if I have this information i can simply use my logic to know if that player is still in game.
Thanks
Abhishek
Tech Support
said
over 8 years ago
If you write the script in ChallengeTurnTakenMessage you can query the message for the next player using
Spark.getData().nextPlayer
Gabriel
A
Abhishek Bansal
said
over 8 years ago
okay thanks !
P
Pedro Faria
said
about 8 years ago
Hi,
I'm having a problem doing consumeTurn on ChallengeTurnTakenMessage
I have two players, and on some instances, when the player 1 takes a turn of event A, he sends the flag next_is_local in order to enable the next turn to skip and go back to that player 1 so he can take a turn of event B.
I previously set a flag next_is_local on the challenge event A to see if it should skip the turn of the next player
var next_is_local = Spark.getScriptData("next_is_local");
if(next_is_local==1){
SparkChallenge.consumeTurn(Spark.getData().nextPlayer);
}
But after sending the Event A when I send an event B request it says it's not player 1's turn, so It seems this lines of code are not running well.
Customer Support
said
about 8 years ago
Hi Pedro,
At first glance it looks like you are setting the Responses scriptData and not the challenge instance's scriptData.
Spark.setScriptData will only set the scriptData of the next Response to that request and wont store it. When ChallengeTurnTakenMessage goes looking for "next_is_local" it's not going to find anything as the message happens after and separately to the LogChallengeEventRequest.
To set the scriptData of the challenge you can do the following:
var challenge = Spark.getChallenge(Spark.data.challengeInstanceId);
challenge.setScriptData("next_is_local", next_is_local); //This is setting the scriptData of the challenge instance and saving it.
Then in ChallengeTurnTakenMessage you need to also get the challengeId, load the challenge and get the scriptData:
var challenge = Spark.getChallenge(Spark.getData().challenge.challengeId);
var next_is_local = challenge.getScriptData("next_is_local");
if(next_is_local==1){
challenge.consumeTurn(Spark.getData().nextPlayer);
}
Shane
P
Pedro Faria
said
about 8 years ago
Thanks Shane,
that solves part of the problem but It still not consuming the next player's turn, seems like Spark.getData().nextPlayer is returning "undefined"
None of these examples are working for me. I'm in a normal event (not a challenge event). I am using Spark.getChallenge("somechallengeid") to get a challenge object, and then nextPlayer is undefined. How do I get nextPlayer?
The API doesn't seem to give access to nextPlayer or Turns properties of a challenge, but I need both of those.
M
Marcel Piestansky
said
about 7 years ago
Hi Rich,
As you pointed out, the SparkChallenge object in CloudCode does not expose the nextPlayer property. You will need to store this value manually in the challenge's scriptData. I do it myself like this in both ChallengeStartedMessage and ChallengeTurnTakenMessage:
var challenge = Spark.getChallenge( Spark.getData().challenge.challengeId );
challenge.setScriptData( "nextPlayer", Spark.getData().challenge.nextPlayer );
This makes it possible to get the value even in normal events, provided that you have the challenge's ID.
I am not exactly sure what you mean by "turns properties" but I imagine you could use the same approach as above for other data.
Abhishek Bansal
Hi,
I am making a turn based last man standing game which means that I will have to skip turns of the players who are no longer part of challenge. How can I skip turn at server side ?
Thanks
Abhishek Bansal
Hi Abhishek
If you call SparkChallenge.consumeTurn(String playerId) the turn token will be moved to the next player.
You could use this along with your own logic to skip the players who are no longer "standing"
Hope thats useful
Gabriel
- Oldest First
- Popular
- Newest First
Sorted by Oldest FirstTech Support
Hi Abhishek
If you call SparkChallenge.consumeTurn(String playerId) the turn token will be moved to the next player.
You could use this along with your own logic to skip the players who are no longer "standing"
Hope thats useful
Gabriel
Abhishek Bansal
Hi Gabriel,
Will try this !
Thanks
Abhishek Bansal
Hi Gabriel !
I am confused with where to call this ?
in challenge events ?
How can I know the who is the next turn.. if I have this information i can simply use my logic to know if that player is still in game.
Thanks
Abhishek
Tech Support
If you write the script in ChallengeTurnTakenMessage you can query the message for the next player using
Spark.getData().nextPlayer
Gabriel
Abhishek Bansal
okay thanks !
Pedro Faria
Hi,
I'm having a problem doing consumeTurn on ChallengeTurnTakenMessage
I have two players, and on some instances, when the player 1 takes a turn of event A, he sends the flag next_is_local in order to enable the next turn to skip and go back to that player 1 so he can take a turn of event B.
I previously set a flag next_is_local on the challenge event A to see if it should skip the turn of the next player
Then on ChallengeTurnTakenMessage
But after sending the Event A when I send an event B request it says it's not player 1's turn, so It seems this lines of code are not running well.
Customer Support
Hi Pedro,
At first glance it looks like you are setting the Responses scriptData and not the challenge instance's scriptData.
Spark.setScriptData will only set the scriptData of the next Response to that request and wont store it. When ChallengeTurnTakenMessage goes looking for "next_is_local" it's not going to find anything as the message happens after and separately to the LogChallengeEventRequest.
To set the scriptData of the challenge you can do the following:
Then in ChallengeTurnTakenMessage you need to also get the challengeId, load the challenge and get the scriptData:
Shane
Pedro Faria
Thanks Shane,
that solves part of the problem but It still not consuming the next player's turn, seems like Spark.getData().nextPlayer is returning "undefined"
Tested this line both on the LogChallengeEvent A and then on ChallengeTakenTurnMessage both set TEST:"undefined" on challenge script data.
Customer Support
Hi Pedro,
As nextPlayer is stored in the challenge Object on the ChallengeTakenTurnMessage this line of code actually needs to be:
Shane
Rich Joslin
None of these examples are working for me. I'm in a normal event (not a challenge event). I am using Spark.getChallenge("somechallengeid") to get a challenge object, and then nextPlayer is undefined. How do I get nextPlayer?
The API doesn't seem to give access to nextPlayer or Turns properties of a challenge, but I need both of those.
Marcel Piestansky
Hi Rich,
As you pointed out, the SparkChallenge object in CloudCode does not expose the nextPlayer property. You will need to store this value manually in the challenge's scriptData. I do it myself like this in both ChallengeStartedMessage and ChallengeTurnTakenMessage:
This makes it possible to get the value even in normal events, provided that you have the challenge's ID.
I am not exactly sure what you mean by "turns properties" but I imagine you could use the same approach as above for other data.
Marcel
Rich Joslin
Ahh, that's a good idea. Thanks!
-
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