Got a relatively simple problem that has me stumped tonight and figured I should post here for help before tearing out my hair.
I've got a property, Skills, and for a selected token, the value of Skills is an array of JSON objects:
Code: Select all
[{"skillName":"Dodge","attribute":"DEX","skillCode":"4D+1"},{"skillName":"Melee Parry","attribute":"DEX","skillCode":"3D+2"}]
Then, I have a function to iterate through this list of skills and then return the skillCode of a matching skillName. I've tested the function up & down several times and it's getting arguments passed to it correctly.
Code: Select all
[h: token = arg(0)]
[h: skillFind = arg(1)]
[h: skillCode = "2D"]
[h: skillName = ""]
[h: skillProp = getProperty("Skills", token)]
[h, foreach(skill, skillProp), CODE:
{
[skillName=json.get(skill,"skillName")]
[skillCode = if(skillName == skillFind, json.get(skill, "skillCode", skillCode))]
}]
[h: macro.return = skillCode]
So this function is correctly receiving the token ID, it retrieves the Skill property, and it reads the Skill names. But it simply cannot evaluate where, if the first argument is "Dodge", this string equals the skillName value of the first skill JSON object it encounters in the array. Or, I pass "Melee Parry", it doesn't recognize this string equating to the value of skillName for the 2nd object.
Any idears out there where I've goofed on this? Like I said, I am
stumped!! Please save my scalp.