Why is this if failing?

Thoughts, Help, Feature Requests, Bug Reports, Developing code for...

Moderators: dorpond, trevor, Azhrei

Forum rules
PLEASE don't post images of your entire desktop, attach entire campaign files when only a single file is needed, or generally act in some other anti-social behavior. :)
Post Reply
User avatar
celestian
Dragon
Posts: 276
Joined: Mon May 17, 2010 3:29 pm

Why is this if failing?

Post by celestian »

This works:

Code: Select all

[spellInfo = json.get(sk,spellName)]
[count = json.get(spellInfo,'count')]
and this fails:

Code: Select all

[spellInfo = json.get(sk,spellName)]
[if (spellInfo != ''): count = json.get(spellInfo,'count')]
The only difference is I am trying to make sure spellInfo is not ''. I've tried !json.isEmpty(spellInfo) also and it fails also.

Code: Select all

   Error in body of roll.       Statement options (if any): if (spellInfo != '')       Statement Body : count = json.get(spellInfo,'count')

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

Re: Why is this if failing?

Post by aliasmask »

This should work:

Code: Select all

[spellInfo = json.get(sk,spellName)]
[if(! json.isEmpty(spellInfo)): count = json.get(spellInfo,'count')]
Sometimes I forget the 2nd ) which could account for your error. Also, if spellInfo is not a json, the get will give you an error. You could add this:

Code: Select all

[spellInfo = json.get(sk,spellName)]
[if(! json.isEmpty(spellInfo) && json.type == "OBJECT"): count = json.get(spellInfo,'count')]

User avatar
celestian
Dragon
Posts: 276
Joined: Mon May 17, 2010 3:29 pm

Re: Why is this if failing?

Post by celestian »

aliasmask wrote:This should work:

Code: Select all

[spellInfo = json.get(sk,spellName)]
[if(! json.isEmpty(spellInfo)): count = json.get(spellInfo,'count')]
Sometimes I forget the 2nd ) which could account for your error. Also, if spellInfo is not a json, the get will give you an error. You could add this:

Code: Select all

[spellInfo = json.get(sk,spellName)]
[if(! json.isEmpty(spellInfo) && json.type == "OBJECT"): count = json.get(spellInfo,'count')]
Thanks!

Had to make a slight tweak to your code to make it work (json.type(var)) but it worked just like I needed.

Code: Select all

[if(! json.isEmpty(sk) && json.type(sk) == "OBJECT"):  spellInfo = json.get(sk,spellName);spellInfo='']
[if(! json.isEmpty(spellInfo) && json.type(spellInfo) == "OBJECT"): count = json.get(spellInfo,'count')]
The test for OBJECT was the bit that seemed to make the difference!

Post Reply

Return to “MapTool”