RPTools.net

Discussion and Support

Skip to content

It is currently Sat Feb 24, 2018 5:27 am 






Reply to topic  [ 3 posts ] 

Previous topic | Next topic 

  Print view

Author Message
 Offline
Kobold
 
Joined: Thu Jan 28, 2016 9:17 pm
Posts: 15
 Post subject: What is wrong with my code
PostPosted: Sat Jul 16, 2016 7:21 pm 
Maptools Ver: 1.4

What is wrong with the following

Code:
[r, if (result == ""): result = wepstr ; result = result + "," + wepstr ]

I am getting the following error:
  Invalid condition in IF(result == "") roll option.       
Statement options (if any): r, if (result == "")       
Statement Body : result = wepstr ; result = result + "," + wepstr

At this point I am at a complete loss because I just can't figure it out. If I reverse the actions it works fine: if (result == ""): result = result + "," + wepstr ; result = wepstr
But then the output is wrong and isn't usable. If I make it a != again it works but doesn't give a valid result. If I use the != and shift the assignments to be the correct order, then again I get the error. I've include the input data, the entire macro code and a sample of the output to the chat window.

What on earth have I done wrong?

Thanks in advance.


This is the input data:
Code:
["weapon.name=Scimitar;weapon.tohit=4;weapon.damage=1d6+2;weapon.type=slashing;weapon.critdie=d6;weapon.note=","weapon.name=Shortbow;weapon.tohit=4;weapon.damage=1d6+2;weapon.type=piercing;weapon.critdie=1d6;weapon.note="]


This is the Macro Code:
Code:
[h: str = macro.args]

[h: result = ""]
[foreach(w, str), code:
{
   [h: wepstr = ""]
   [foreach(fld, w, "", ";"), code:
   {
      [h: newval = replace(fld, "weapon.", "")]
      [h, if (wepstr != ""): wepstr = wepstr + ',"' + replace(newval, "=", '":"') + '"' ; wepstr = '{"' + replace(newval, "=", '":"') + '"']
   }]

   [h: wepstr = wepstr + ',"range":"5"' + ',"magic":"0"' ]

[h: Output("convert: a: wepstr: " + wepstr, "all", getSelected())]
   
   [h, if ( ! startsWith(wepstr, "{")): wepstr = "{" + wepstr]
   [h, if (! endsWith(wepstr, "}")): wepstr = wepstr + "}"]

[h: Output("convert: b: wepstr: " + wepstr, "all", getSelected())]
[h: Output("convert: a: result " + result, "all", getSelected())]

[b]   [r, if (result == ""): result = wepstr ; result = result + "," + wepstr ]
[/b]

[h: Output("convert: b: result " + result, "all", getSelected())]
}]
[h:result = strformat( "[%s]", result)]
[h: Output("convert: result " + result, "all", getSelected())]

[h: macro.return = result]


Chat window output:
Quote:
lib:GlobalMacros:
Calling Convert
lib:GlobalMacros:
convert: a: wepstr: {"name":"Scimitar","tohit":"4","damage":"1d6+2","type":"slashing","critdie":"d6","note":"","range":"5","magic":"0"
lib:GlobalMacros:
convert: b: wepstr: {"name":"Scimitar","tohit":"4","damage":"1d6+2","type":"slashing","critdie":"d6","note":"","range":"5","magic":"0"}
lib:GlobalMacros:
convert: a: result
lib:GlobalMacros:
convert: b: result {"name":"Scimitar","tohit":"4","damage":"1d6+2","type":"slashing","critdie":"d6","note":"","range":"5","magic":"0"}
lib:GlobalMacros:
convert: a: wepstr: {"name":"Shortbow","tohit":"4","damage":"1d6+2","type":"piercing","critdie":"1d6","note":"","range":"5","magic":"0"
lib:GlobalMacros:
convert: b: wepstr: {"name":"Shortbow","tohit":"4","damage":"1d6+2","type":"piercing","critdie":"1d6","note":"","range":"5","magic":"0"}
lib:GlobalMacros:
convert: a: result {"name":"Scimitar","tohit":"4","damage":"1d6+2","type":"slashing","critdie":"d6","note":"","range":"5","magic":"0"}
   Invalid condition in IF(result == "") roll option.       Statement options (if any): r, if (result == "")       Statement Body : result = wepstr ; result = result + "," + wepstr


Top
 Profile  
 
User avatar  Offline
Deity
 
Joined: Tue Nov 10, 2009 6:11 pm
Posts: 8012
Location: Bay Area
 Post subject: Re: What is wrong with my code
PostPosted: Sat Jul 16, 2016 8:56 pm 
I recommend doing this:

Code:
[r, if(json.isEmpty(result)): result = wepstr ; result = result + "," + wepstr ]


When comparing result to a string, result must also be a string and if not then it may give an error. Using the json.isEmpty allows you to do a check with strings, numbers, jsons and even null. You may want to debug the value of result before the if statement to determine what is wrong.

_________________
Downloads:


Top
 Profile  
 
 Offline
Kobold
 
Joined: Thu Jan 28, 2016 9:17 pm
Posts: 15
 Post subject: Re: What is wrong with my code
PostPosted: Sun Jul 17, 2016 12:28 am 
That fixed it.

Thank you. I should have thought of that myself.


Top
 Profile  
 
Display posts from previous:  Sort by  
Reply to topic  [ 3 posts ] 

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:

Who is online

In total there is 1 user online :: 0 registered, 0 hidden and 1 guest (based on users active over the past 5 minutes)
Most users ever online was 243 on Sun Nov 04, 2012 6:14 am

Users browsing this forum: No registered users and 1 guest





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

Style based on Andreas08 by Andreas Viklund

Style by Elizabeth Shulman