Sign In Register

How can we help you today?

Start a new topic

Asynchronous turned-based games

I am trying to create an ansynchronous turn-based game that basically works like chess or words with friends where a player can start a game against a random opponent but can take their turn at any time as long as the turn is made in a time limit of 1 week for example. When a player attempts to find a random match they will either make the 1st move and then wait for another player to get matched to that game or get matched into a game where the 1st move is already made and then make the 2nd move. The actual matchmaking should be based on skill level or other criteria.

I want to matchmaking to work similar to the Heartstone example but the actual mechanics of the matching to work like the turn based challenge tutorial. In the heartstone example it feels as though the expectation is that both players are online during the matchmaking and for the turn based challenge tutorial, I am not sure how to make that work with random skill based matching.

Is this possible and any advice on how to do this?

1 person has this question

I tried this by modifying CreateChallengeRequest with

var someData=;

and verified that someData does have a value in CreateChallengeRequest

However using the line as you suggested in CreateChallengeResponse

var someData=; is undefined

How does this line, var someData=;

actually pass the value of someData to in CreateChallengeResponse? On the surface it seems all this would do is to store the value of someData in the script data to a local variable unless something else is happening that is not obvious.

Hi Jaayden,

If you send a CreateChallengeRequest that looks like this (with your challenge parameters set correctly):


  "@class": ".CreateChallengeRequest",

  "scriptData": {

    "firstMove": "Player 1 move data"


// Other parameters for CreateChallengeRequest


Then in cloud code for CreateChallengeRequest, add these lines:

var firstMove = Spark.getData().scriptData.firstMove;

Spark.setScriptData("firstMove", firstMove);

This will set the "firstMove" field on the response script data which is accessible from the response cloud code.

Now in CreateChallengeResponse code:

var firstMove = Spark.getScriptData("firstMove");

var currentChallenge = Spark.getChallenge(Spark.getData().challengeInstanceId);

currentChallenge.setScriptData("firstMove", firstMove);

This will result in the challenge being created with scriptData containing the "firstMove" data you passed up in the CreateChallengeRequest.

Hope this helps,


How do I take script data from the CreateChallengeRequest and store that in the challenges scriptData? I thought the challenge would not actually be created yet or maybe I just do not know how to access it.

Hi Jaayden, 

This is the way you'd save some data from Create Challenge Request to a Challenge scriptData:

In the request's Cloud code:

//Set value of virtualGoodWager

var someData=;

This piece of code will now forward this scriptData to the CreateChallenge Response. Now in the CreateChallenge Response Cloud Code, have this:

//Get the scriptdata from the request that we forwarded

var someData=;

//Load the challenge, you'll be able to get the challenge ID because we've just created it

var currentChallenge = Spark.getChallenge(Spark.getData().challengeInstanceId);

//Set scriptData

currentChallenge.setScriptData("someData", someData);   

Hope this helps,


I asked this before, if im not mistaken, MatchMakingRequests are for both online players only. Since the mechanics of your game will have optional online players, then 

First player Creates challenge.

Store the challenge is a runtimeCollection / DataType

2nd player fetches available open challenges.

2nd player then can join.

Move the challenge to a different collection or remove it entirely from that colelction so no 3rd player could join. 

Depends on ur game

Hi Jaayden,

What you could do here is have a player take the first move before the challenge has been created, when that first move has been completed successfully have the player create a challenge with a CreateChallengeRequest and store that initial move in the challenges scriptData. Then when another player joins the challenge the data from the first move can be used to update the new players board and the game can continue from there. Does that make sense ? If you have any further questions just let us know.



I'm looking to do something similar to this too.  One question, how do other players go about joining this challenge?  It looks like the first player creates a challenge directly with a CreateChallengeRequest.  How do other players looking for a game join this created challenge?  Do they do a MatchmakingRequest?  If so, how does the MatchmakingRequest know how to find this already created challenge?  Does the first player also have to create a MatchmakingRequest too?

Please advise,



Login to post a comment