Sign In Register

How can we help you today?

Start a new topic

GSDataList is empty although value gets returned in test harness

I have a string list, that I want to iterate through in Cloud Code like this:

 

var modIdString = Spark.getData().LVL_ID_LIST;
var modIdArray = modIdString.split(";");
var modIdArrayLength = modIdArray.length;
var results = [];

for (var i = 0; i < modIdArrayLength; i++) {
    var lvl = gameConfigsCollection.find({"_id":{"$oid":modIdArray[i]}});
    results.push(lvl);
}
Spark.setScriptData("data", results);

  

The array "results" gets filled and should finally be returned with


Interestingly, when testing the code in test harness, it works, but the format of the return values is different then usual:

   

{
  "@class": ".LogEventResponse",
  "scriptData": {
    "data": [
      [  <== this bracket is extra
        {
            //Value one
        }
      ],
      [
        {
           //Value two
        }
      ]
    ]
  }
} 

   Working, usual format on a different event:

 

{
  "@class": ".LogEventResponse",
  "scriptData": {
    "data": [
      {
      },
      {
      }
    ]
  }
}

 

Now in Unity the gsDataList is empty. Why?

Is it beacause it's an array, different syntax? How do I solve this or is there maybe a better/more simple way to do what I want to do?


Thank you and all the best!

Benedikt


 Hey Benedikt,

Could you send us an example of the data-structure you are trying to send back?

Thanks,
Sean

Hey Sean,


Sure. So I'm trying to get all levels (game configurations) from the collection GameConfiguration that are needed according to a levelId list, which is requested from Unity.

The json structure of one level looks like this

  

{
  "_id": {
    "$oid": "59ef37961f22be050a6bfb8c"
  },
  "DisabledSyllableOrthographies": [
    "Unstressed",
    "Stressed",
  ],
  "EnabledSyllableOrthographies": [
    "Closed_Doubling_CK",
    "Closed_Doubling_TZ",
  ],
  "EnabledSyllableOrthographiesFrequencyDistribution": null,
  "Environment": {
    "Environment": "TheGreatRiver_06",
    "Fireflies": true
  },
  "GameConfiguration": {
    "M01Game06Configuration": {
      "DisplaySyllableArcs": false,
      "DistractorMode": "Confusion",
      "KeypadMode": "Chaos",
      "NumberOfLettersKnown": false,
      "OrthosodiyaInterfaceDifficulty": "OrthographyBeginner1",
      "ShiftMode": "Automatic"
    }
  },
  "GameType": "M01Game06",
  "IsAutomationTask": true,
  "MaxNumberOfCompletions": 0,
  "MinNumberOfCompletions": 3,
  "Name": "@P_M01CH06SC02LVL05",
  "Number": 5,
  "NumberOfTasks": 10,
  "TrialsPerTask": 3,
  "UnlockNextConfigurationCondition": 0
}

In Unity I image to access it as i usually do

 

var gsData = response.ScriptData.GetGSDataList("data");
var lvl1 = JsonConvert.DeserializeObject<Level>(gsData[0].JSON);

 

Thank you!

Solution:

I ended up using "findOne" command instead of "find". It returnes a JSON and not a cursor, so the array gets filled directly with jsons.

Login to post a comment