What is wrong with the following
Code: Select all
[r, if (result == ""): result = wepstr ; result = result + "," + wepstr ]
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: Select all
["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="]
Code: Select all
[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]
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