Can't look for boolean value in a dictionary

Bugs will be moved here once resolved.

Post » Mon Oct 14, 2013 1:51 am

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..
http://www.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!Rushino2013-10-14 02:03:05
B
16
S
5
G
1
Posts: 190
Reputation: 2,489

Post » Mon Oct 14, 2013 5:08 am

This isn't actually a bug

Dictionary only stores STRINGS and NUMBERS.
https://www.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.jayderyu2013-10-14 05:09:20
B
90
S
18
G
9
Posts: 2,455
Reputation: 15,018

Post » Mon Oct 14, 2013 3:38 pm

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.. http://www.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.Rushino2013-10-14 21:52:04
B
16
S
5
G
1
Posts: 190
Reputation: 2,489

Post » Fri Oct 18, 2013 7:41 pm

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.
Scirra Founder
B
395
S
231
G
88
Posts: 24,367
Reputation: 193,694

Post » Fri Oct 18, 2013 9:58 pm

Its k anyway i decided to not use the boolean form but 0 and 1 from now. Thanks for clarifiying this out.
B
16
S
5
G
1
Posts: 190
Reputation: 2,489

Post » Fri Oct 18, 2013 10:06 pm

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 ?
B
16
S
5
G
1
Posts: 190
Reputation: 2,489


Return to Closed bugs

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest