This macro cycles through the table, presents a LIST of weapons, and then is supposed to add the selected weapon to the selected token. It works fine, except that it always adds the weapon from row #2 of my table. In other words, the variable weaponNum is always set to = 1. BTW, the variable rangedWeapons is the token's property, a JSON array holding a list of JSON object.
Code: Select all
[h: rangedWeaponsAll = ""]
[h: wpnName = ""]
[h, for(x, 1, 7, 1, ""), code: {
[h: wpnRow = table("RangedWeapons", x)]
[h: wpnName = wpnName + "," + json.get(wpnRow, "WeaponName")]
<!-- rangedWeaponsAll is a JSON array of all Ranged Weapons -->
[h: rangedWeaponsAll = json.append(rangedWeaponsAll, table("RangedWeapons", x))]
}]
[h: wpnName = trim(wpnName)]
[h: wpnName = substring(wpnName, 1, length(wpnName))]
[h: weaponNum=input("varName|" + wpnName + "|Select Ranged Weapon to Add to Token|LIST|SELECT=0")]
[h: RangedWeapons = json.append(rangedWeapons, json.get(rangedWeaponsAll, weaponNum))]