Sign In Register

How can we help you today?

Start a new topic

Cannot start a challenge.

hi,


i pretty new to Game spark. I am following this tutorial to build a turn base multiplayer game.


http://blog.theknightsofunity.com/turn-based-multiplayer-game-gamesparks-unity-1/


i am having an issue when two players logged in both receive match found massage. But match issue massage is only received by  the second player. Both players got same match id. 


here is my Cloud code logic for MatchFoundMessage

if(Spark.getData().matchShortCode === "DefaultMatch"){

    if (Spark.getPlayer().getPlayerId() === Spark.getData().participants[0].id) {

       var tomorrow = new Date();

       tomorrow.setDate(tomorrow.getDate() + 1);

       var request = new SparkRequests.CreateChallengeRequest();

       request.challengeShortCode = "DefaultChallenge";

       request.endTime = tomorrow.toISOString();

       request.usersToChallenge = Spark.getData().participants[1].id;

       request.Send();

    }

}



here is my Cloud code logic for ChallengeIssuedMessage

var chalData = Spark.getData();

var request = new SparkRequests.AcceptChallengeRequest();

request.challengeInstanceId = chalData.challenge.challengeId;

request.SendAs(chalData.challenge.challenged[0].id);


here is my Cloud code logic for ChallengeStartedMessage

var chal = Spark.getChallenge(Spark.getData().challenge.challengeId);


//Player IDs

var challengerId = chal.getChallengerId();

var challengedId = chal.getChallengedPlayerIds()[0];


//Construct the play field JSON - Used for the playing field

var playField = {};

playField[challengerId] = {};

playField[challengedId] = {}



Login to post a comment