Page 1 of 1

json.contains help

Posted: Sun Jan 07, 2018 10:11 am
by jackolas
I might be looking over something but why is this code always reporting false for me? (maptool 1.4.0.5)

Code: Select all

[R: RNA_Array = json.append("", 0, 0, 0, 1)]<br>
[R: RNA_Compair = 1]<br>

[R: json.contains(RNA_Array, RNA_Compair)]<br>

[R: if(json.contains(RNA_Array, RNA_Compair), "true", "false")]

Re: json.contains help

Posted: Sun Jan 07, 2018 1:21 pm
by JamzTheMan
I've had issues putting json functions directly into an IF statement before, but I haven't looked at the code yet so don't know the technical reason yet (suspect return type isn't a BigInteger or something along those lines...

You can avoid this by assigning to a variable first and then testing:

Code: Select all

[R: RNA_Array = json.append("", 0, 0, 0, 1)]<br>
[R: RNA_Compair = 1]<br>

[R: result = json.contains(RNA_Array, RNA_Compair)]<br>

[R: if(result, "true", "false")]
Probably a bug to look into...

Re: json.contains help

Posted: Sun Jan 07, 2018 1:48 pm
by jackolas
k. was just checking that i did not make a mistake :P

btw. thats exactly the way i solved it atm.

Re: json.contains help

Posted: Sun Jan 07, 2018 3:33 pm
by aliasmask
I've had problems with the return type of some function where putting them in to their own variable before using them in a function solved the problem for me. This one surprises me a little since if used to be so forgiving.

I checked some other comparisons:

Code: Select all

[r, if("1"):1;0)]
this throws an error

Code: Select all

[r, if("1"==1):1;0)]
this returns 1

notice how the "1" is converted for the comparison, but not as a stand alone result. I'm okay with either logic, but it should be done consistently.

At one point I believe having a non-zero as an if condition resulted in true. So, strings, floats and anything but a zero or "false" (reserved word) would return true. I think the only thing that really threw an error was if the condition was null.