json.contains help

Discuss macro implementations, ask for macro help (to share your creations, see User Creations, probably either Campaign Frameworks or Drop-in Resources).

Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice

Post Reply
User avatar
jackolas
Cave Troll
Posts: 28
Joined: Tue Apr 16, 2013 8:19 am
Location: Netherlands
Contact:

json.contains help

Post 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")]

User avatar
JamzTheMan
Great Wyrm
Posts: 1872
Joined: Mon May 10, 2010 12:59 pm
Location: Chicagoland
Contact:

Re: json.contains help

Post 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...
-Jamz
____________________
Custom MapTool 1.4.x.x Fork: maptool.nerps.net
Custom TokenTool 2.0 Fork: tokentool.nerps.net
More information here: MapTool Nerps! Fork

User avatar
jackolas
Cave Troll
Posts: 28
Joined: Tue Apr 16, 2013 8:19 am
Location: Netherlands
Contact:

Re: json.contains help

Post by jackolas »

k. was just checking that i did not make a mistake :P

btw. thats exactly the way i solved it atm.

User avatar
aliasmask
RPTools Team
Posts: 9024
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: json.contains help

Post 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.

Post Reply

Return to “Macros”