Sign In Register

How can we help you today?

Start a new topic

Cannot receive challenge accept call back

hi,

i am pretty new to Game Spark. I am following this tutorial.

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


i am having an issue that. When two players logged in they both receive match found massage and their MatchId is also same. But only the Second Player receive "OnChallengeIssued" callback. Both does not receive "ChallengeAccept" callback.


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] = {}


Can you help?please

Login to post a comment