Sign In Register

How can we help you today?

Start a new topic
Answered

Unity ChallengeStartedMessage - scriptData is null

I am having difficulties when restarting challenge with Unity and Test Harness. 


When I do this steps, got null for scriptData in ChallengeStartedMessage:

  1. login to Test Harness with "user1".
  2. login to Unity with "user2".
  3. challenge started
  4. user1 disconnects from Test Harness and clears a chache in Chrome
  5. user1 again login to TestHarness
  6. user2 also disconnects from Unity and then relogin
  7. Challenge Starts
  8. user2 receieves null for ScritpData in ChallengeStartedMessage while user1 got scriptData
 

Following json is message from Unity:

 

{
  "@class": ".ChallengeStartedMessage",
  "challenge": {
    "accepted": [
      {
        "externalIds": { },
        "id": "5734c1e61474e704c746f508",
        "name": "miro"
      },
      {
        "externalIds": { },
        "id": "5734c1f8808eb904a09bea6b",
        "name": "pero"
      }
    ],
    "challengeId": "573b5151808eb904a05e6815",
    "challengeName": "Ranked Challenge",
    "challenged": [
      {
        "externalIds": { },
        "id": "5734c1e61474e704c746f508",
        "name": "miro"
      }
    ],
    "challenger": {
      "externalIds": { },
      "id": "5734c1f8808eb904a09bea6b",
      "name": "pero"
    },
    "endDate": "2018-02-23T13:47Z",
    "expiryDate": "2018-02-23T12:47Z",
    "nextPlayer": "5734c1e61474e704c746f508",
    "scriptData": { },
    "shortCode": "chalRanked",
    "startDate": "2016-05-17T17:13Z",
    "state": "RUNNING",
    "turnCount": {
      "5734c1e61474e704c746f508": 0,
      "5734c1f8808eb904a09bea6b": 0
    }
  },
  "messageId": "573b5151808eb904a05e6825",
  "notification": true,
  "playerId": "5734c1e61474e704c746f508",
  "summary": "Ranked Challenge is good to go."
}

 
And this is from GameSparks:

 

GameSparks
==============

{
 "@class": ".ChallengeStartedMessage",
 "challenge": {
  "accepted": [
   {
    "externalIds": {},
    "id": "5734c1e61474e704c746f508",
    "name": "miro"
   },
   {
    "externalIds": {},
    "id": "5734c1f8808eb904a09bea6b",
    "name": "pero"
   }
  ],
  "challengeId": "573b5151808eb904a05e6815",
  "challengeName": "Ranked Challenge",
  "challenged": [
   {
    "externalIds": {},
    "id": "5734c1e61474e704c746f508",
    "name": "miro"
   }
  ],
  "challenger": {
   "externalIds": {},
   "id": "5734c1f8808eb904a09bea6b",
   "name": "pero"
  },
  "endDate": "2018-02-23T13:47Z",
  "expiryDate": "2018-02-23T12:47Z",
  "nextPlayer": "5734c1e61474e704c746f508",
  "scriptData": {
   "playField": {
    "5734c1f8808eb904a09bea6b": {},
    "5734c1e61474e704c746f508": {}
   },
   "currentHand": {
    "5734c1f8808eb904a09bea6b": {
     "c0": {
      "type": "Red Dragon",
      "atk": 5,
      "hp": 3,
      "maxHP": 3,
      "spawnCost": 4,
      "effect": "Fire Breathe"
     },
     "c1": {
      "type": "Warrior",
      "atk": 1,
      "hp": 2,
      "maxHP": 2,
      "spawnCost": 1,
      "effect": "Charge"
     },
     "c2": {
      "type": "Red Dragon",
      "atk": 5,
      "hp": 3,
      "maxHP": 3,
      "spawnCost": 4,
      "effect": "Fire Breathe"
     }
    },
    "5734c1e61474e704c746f508": {
     "c0": {
      "type": "Hunter",
      "atk": 2,
      "hp": 3,
      "maxHP": 3,
      "spawnCost": 1,
      "effect": "Charge"
     },
     "c1": {
      "type": "Hunter",
      "atk": 2,
      "hp": 3,
      "maxHP": 3,
      "spawnCost": 1,
      "effect": "Charge"
     },
     "c2": {
      "type": "Mage",
      "atk": 4,
      "hp": 2,
      "maxHP": 2,
      "spawnCost": 3,
      "effect": ""
     }
    }
   },
   "playerStats": {
    "5734c1f8808eb904a09bea6b": {
     "overallMana": 1,
     "currentMana": 1,
     "playerHealth": 30,
     "cardsPulled": 3,
     "hasPulled": true,
     "tauntProtection": false
    },
    "5734c1e61474e704c746f508": {
     "overallMana": 1,
     "currentMana": 1,
     "playerHealth": 30,
     "cardsPulled": 3,
     "hasPulled": true,
     "tauntProtection": false
    }
   }
  },
  "shortCode": "chalRanked",
  "startDate": "2016-05-17T17:13Z",
  "state": "RUNNING",
  "turnCount": {
   "5734c1e61474e704c746f508": 0,
   "5734c1f8808eb904a09bea6b": 0
  }
 },
 "messageId": "573b5151808eb904a05e6832",
 "notification": true,
 "playerId": "5734c1f8808eb904a09bea6b",
 "scriptData": {
  "result": "Mage was pulled from deck"
 },
 "summary": "Ranked Challenge is good to go."
}

I checked Script.log and there is no error.

Also I tried with challengeEvent in which I call .drawChallenge() before user user1 disconnect, and same result.

Thanks,

Mislav


Best Answer

Guys I am so sorry I totally overlooked one line of code. As I said I was following Hearthstone tutorial.

Blame is on matchmaking tutorial (https://docs.gamesparks.com/tutorials/multiplayer/hearthstone-example/matchmaking.html).

and this line of code in ChallengeStarted cloud code:

 

//Initiation of the challenge settings through the challenger(similar to host)
if(Spark.getPlayer().getPlayerId() === challengerId){

 As I said, in some cases challenged player (not challenger) can get ChallengeStarted message first. In that case scriptData is not set and he got null for scriptData.

Mislav


Hi Mislav,


Is there a reason you are trying to add scriptData to the ChallengeStartedMessage ? You can also set it to the challenge itself using SparkChallenge, you can read more about this here. Is user 2 in the Unity Editor or on a device ? Have you tried fully closing either before re authenticating ? 


Thanks,

Liam

Hey Liam,

I was following Hearthstone tutorial, that's the reason why I fill scriptData in ChallengeStarted :)

User 2 is Editor.

It is rarely happening if I try to reproduce with 2 Chrome test harness instances. But often while one player is Chrome and other is in Unity Editor - I think that Editor player is somehow still cached and authenticated and then after I logout and then login with him, start challenge, got null because GameSparks thinks I am still logged in and in first challenge. 

ChallengeWithdraw didn't make much difference

Can two players start one challenge and then start another one while first one is still running?

Mislav

This cannot be reproduced if Editor player is disconnecting and other is logged in, just if both players disconnects.

Mislav

Hey Liam,

Any news about this problem?

I can confirm that this is not problem with Unity, I can reproduce with 2 test harness windows.

Steps: 

Player 1 finds a match
Player 2 finds a match

Challenge Starts

Player 2 finds a match
Player 1 finds a match

Challenge starts but player 2 got null for challenge script data

It is OK in this steps:

Player 1 finds a match
Player 2 finds a match

Challenge Starts

Player 1 finds a match
Player 2 finds a match

It is true that i starts challenge with same players and that challenge isnt finished yet but manual withdrawn challenge didn't help either. 

Last time that happened was with challengeId: 579600524912893204b89e13


Mislav

Answer

Guys I am so sorry I totally overlooked one line of code. As I said I was following Hearthstone tutorial.

Blame is on matchmaking tutorial (https://docs.gamesparks.com/tutorials/multiplayer/hearthstone-example/matchmaking.html).

and this line of code in ChallengeStarted cloud code:

 

//Initiation of the challenge settings through the challenger(similar to host)
if(Spark.getPlayer().getPlayerId() === challengerId){

 As I said, in some cases challenged player (not challenger) can get ChallengeStarted message first. In that case scriptData is not set and he got null for scriptData.

Mislav

Hi Mislav,


No problem, sincerest apologies for this being post being overlooked. I'm happy to hear you got this one worked out. If you run into any other issues that require immediate attention please log a ticket in our system and our team will get it addressed as fast as possible.


Thanks,

Liam


1 person likes this
Login to post a comment