Can't look for boolean value in a dictionary

0 favourites
  • 6 posts
  • Hello,

    I found the fellowing bug which is currently putting my project on hold (i use a ton of JSON queries)... if you load the dictionary with this fellowing JSON (a JSON with boolean values)

    {"c2dictionary":true,"data":{ "TestWithBoolean":true, "TestWithoutBoolean":"true" }}

    There is no way to detect that the key TestWithBoolean have 'true' as the value. Using the fellowing event: Key "TestWithBoolean" = "true" doesn't work since its not a string but a boolean without quotes.

    The value in the debugging show 'true' for both the key but in real they different.

    I even tried using a for each to write the values to the log of the browser and i got this..

    TestWithBoolean : 0

    TestWithoutBoolean : true

    I would be glad if you could provide a simple workaround for now.

    Link to .capx file (required!):

    Here a simple sample which show the problem..

    mediafire.com/download/rcru7arw9f7cl9g/DictionaryLoadBugWithBooleanAsJSON.capx

    Steps to reproduce:

    1. Load a dictionary with the JSON. {"c2dictionary":true,"data":{ "TestWithBoolean":true, "TestWithoutBoolean":"true" }}

    2. Try to check if TestWithBoolean have the value 'true'. It won't work!

    Observed result:

    There is no way to detect a boolean. The event will never go in.

    Expected result:

    I expected to be able to test if TestWithBoolean had the value 'true' but i couldn't. At least it should detect TRUE and return 1 in that case..

    Browsers affected:

    Chrome: yes!

    Firefox: yes!

    Internet Explorer: yes!

    Operating system & service pack:

    Windows 7 64bits latest service pack...

    Construct 2 version:

    r146

    Thanks for your help!

  • This isn't actually a bug

    Dictionary only stores STRINGS and NUMBERS.

    scirra.com/manual/140/dictionary

    Don't rely on Dictionary to do a BOOLEAN comparison.

    If you need compare boolean. You need to

    int(Dictionary.Value) = 0   // false

    int(Dictionary.Value) != 0 // true

    but I don't believe right now this can be considered a BUG. As BOOLEAN is not a NUMBER.

    However I do actively use a Dictionary for Boolean comparison. I just use the value of 0/1 instead of TRUE/FALSE and have had no problem.

  • I tried converting it. Doesn't work either.. i tried

    int(Dictionary.Get("TestWithBoolean")) = 1 THEN something..

    and

    int(Dictionary.CurrentValue) and i still get 0 after the conversion.

    (you can get the updated sample here.. mediafire.com/download/f3777k3kblq1gac/DictionaryLoadBugWithBooleanAsJSONv2.capx)

    I know booleans aren't number nor string.. but the dictionary object seem (like you said) to allow only string and int comparaison which is a bit odd when you can have booleans values as JSON. Boolean can be (or at least should be) converted to int which could have solved the issue but it doesn't seem to be the case here. You have to agree its a bit confusing :) It may not be a bug.. but could be a feature request then.

    You said your using actively the dictionary for boolean comparaison.. then i would be interested if you could show me exactly what your doing to do that boolean test. Probably something i didn't got right.

    Thanks for your help :)

    EDIT: For now i did a converter on the server side for fixing this issue so i can receive 1 instead of true and 0 instead of false. It work well and also save some bandwidth since true take more space than a single number. Not a big deal but if you receive like 100 elements in an array with boolean that can be nice to have.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Closing as won't fix. Dictionary JSON is a subset of JSON. Since the object only writes strings and numbers, the JSON it reads and writes only supports strings and numbers. The "c2dictionary" key in the root of the object is indicating it's using this special subset, not general purpose JSON.

  • Its k anyway i decided to not use the boolean form but 0 and 1 from now. Thanks for clarifiying this out.

  • Well its ok anyway i decided to not use the boolean form but 0 and 1 from now. Thanks for clarifiying this up.

    But honestly that subset of json is kind of cumbersome and iam pretty sure many would say the same. I may not be aware of why you guys decided to use a subset so im just saying! But there no an huge difference between the subset and json so why not using json directly ?

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)