Sign In Register

How can we help you today?

Start a new topic

Boolean field in a object coming from Game Data Service does not evaluate correctly in a condition


We've come across a bug when getting an entry from the new GDS service. Evaluating a boolean field in the object directly in a condition statement seems to always evaluate as true even if the field is set to false.


var data1 = Spark.getGameDataService().getItem("data", 1).document().getData();
//data1 returns as { "boolValue" : false }

if (!data1.boolValue)
    Spark.getLog().debug("Yay!"); //Should do this since boolValue is false and we're negating it
    Spark.getLog().debug("Wut???"); //But does this instead

// this works normally
if (data1.boolValue != true)
var data2 = { "boolValue" : false }

// this also works normally
if (!data2.boolValue)

Step to reproduce:
1. Create an indexed type with no indexes.
2. Insert  { "boolValue" : false } with ID 1
3. Create an event and use the above code in a event
4. Use test harness to debug the event and observe the weird behaviour when stepping over the code.

We create a server where we've already put all the above steps. Let us know if you want the API key to go see it. We could also create a ticket for it if you'd like.

1 person has this problem
1 Comment

Super annoying behavior... I waste lot of time just because boolean returned from collections are packed into object shells...

There are more similar problems related with data serialization/deserialization in GameSparks:
* deserialized objects has not working hasOwnProperty method, it throws error "Cannot find default value for object",
* dynamically created strings throws "Can't serialize [...].javaScript.constString" or something similar.

For me right now works small workarounds:
* for deserialized objects I can use "JSON.parse(JSON.stringify(objectFromCollection))",
* for problems with string I use "String('My dynamically created text ' + myArg + '.').


Login to post a comment