Sign In Register

How can we help you today?

Start a new topic
Answered

Start match and next player problems

Hi!


page https://docs.gamesparks.com/tutorials/multiplayer/hearthstone-example/matchmaking.html


In findMatch Event there is error. There should be "matchRanked" instead "rankedMatch", because everywhere else is "matchRanked".

And also seems like in Match Found Message, script doesn't create challenge. It doesn't do anything. But if I create this request in Test Harness, it works.


here is code I wrote to create match with event, but it doesn't create match

I wrote specific challenged player id

-----------------------

 var tomorrow = new Date();

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

        var inHalfMinute = new Date();

        inHalfMinute.setSeconds(inHalfMinute.getSeconds() + 20);

        var inOneMin = new Date();

        inOneMin.setMinutes(inOneMin.getMinutes() + 1);

        

        

        

        //Create a challenge request

        var request = new SparkRequests.CreateChallengeRequest();

        request.accessType = "PRIVATE";

        request.challengeShortCode = "chalRanked";

        request.endTime = tomorrow;

        request.expiryTime = inHalfMinute;

        request.startTime = inOneMin;

        request.usersToChallenge = ["57daddf292c95a70de9fbb21"];

        request.maxPlayers = 2;

        request.minPlayers = 2;

        request.silent = false;

        request.message = "WHAT?";

        request.SendAs(Spark.getPlayer().getPlayerId());


        //Send the request

        // request.Send();

-----------------------


also when match started, when  I call 

challenge.takeTurn(challenge.nextPlayer);

or

challenge .consumeTurn(challenge.nextPlayer);

nextPlayer stays the same


Best Answer

Try to use:


  

Spark.setScriptData(request.SendAs(Spark.getPlayer().getPlayerId());

 

It will return the response and you can see if there's any errors. I do advise that you manually call the match through test harness using the matchmaking request just to see that everything works fine before going to Cloud Code.


Sorry yeah I forgot to add that challenge.setNextPlayer() doesnt work right now. I will put a feature request in for it.


Cheers,

Omar


Hi Viacheslav,


I didn't realise we haven't changed rankedMatch to matchRanked on the docs yet. I got that changed, it will reflect in the next Doc update, cheers for catching it.


And I suspect you can't  create a challenge because you're feeding it the wrong date format. your format gives you:


"Mon May 15 2017 09:47:45 GMT-0000 (UTC)"


The correct format needed is :


"2017-05-15T10:43Z"


Here's a snippet that will help you create this format for your dates:

 

var tomorrow = new Date();
tomorrow.setDate(tomorrow.getDate() + 1);

var inHalfMinute = new Date();
inHalfMinute.setSeconds(inHalfMinute.getSeconds() + 20);

var inOneMin = new Date();
inOneMin.setMinutes(inOneMin.getMinutes() + 1);

//Turn to ISO string format
var tomorrowISO = tomorrow.toISOString();
var inHalfMinuteISO = inHalfMinute.toISOString();
var inOneMinISO = inOneMin.toISOString();

//Cull the string and add Z at the end to suffice Challenge time format
tomorrowCorrectFormat  = tomorrowISO.substr(0,16) + "Z";
inHalfMinuteCorrectFormat  = inHalfMinuteISO.substr(0,16) + "Z";
inOneMinCorrectFormat  = inOneMinISO.substr(0,16) + "Z";
 

  

Hope this helps,

Omar



didn't help


but, as I said, if I paste all the same parameters in test harness's createChallenge request it works.

{

  "@class": ".CreateChallengeRequest",

  "accessType": "PRIVATE",

  "autoStartJoinedChallengeOnMaxPlayers": false,

  "challengeMessage": "",

  "challengeShortCode": "chalRanked",

  "currency1Wager": 0,

  "currency2Wager": 0,

  "currency3Wager": 0,

  "currency4Wager": 0,

  "currency5Wager": 0,

  "currency6Wager": 0,

  "eligibilityCriteria": {},

  "endTime": "2017-05-15T13:14Z",

  "expiryTime": "2017-05-15T13:14Z",

  "maxAttempts": 0,

  "maxPlayers": 2,

  "minPlayers": 2,

  "silent": false,

  "startTime": "2017-05-15T13:14Z",

  "usersToChallenge": [

    "57daddf292c95a70de9fbb21"

  ]

}



also when match started, when I call 

challenge.takeTurn(challenge.nextPlayer);

or

challenge .consumeTurn(challenge.nextPlayer);

nextPlayer stays the same

Answer

Try to use:


  

Spark.setScriptData(request.SendAs(Spark.getPlayer().getPlayerId());

 

It will return the response and you can see if there's any errors. I do advise that you manually call the match through test harness using the matchmaking request just to see that everything works fine before going to Cloud Code.


Sorry yeah I forgot to add that challenge.setNextPlayer() doesnt work right now. I will put a feature request in for it.


Cheers,

Omar


1 person likes this

Creation works now. Didn't know about that kind of debugging. Thanks!


Is there any way to change current player in turn base game?

cause now when I send ChallengeEvent from the "not next player", I get error

"error": {
    "challengeInstanceId": "NOT_YOUR_TURN"
  }
I can use ChatOnChallengeRequest to send data, but If it's possible to use RequestEvents, it'll be great

Hey VIacheslav,


You can use Log Event Requests with a string attribute for challenge instance id and send/save/get data from challenge without it having to be the players turn. Calling a Challenge Log Event requires you to be the 'nextPlayer'. You can still use a normal log event request and reference the challenge. 


Hope that helps,

Omar


1 person likes this
Login to post a comment