I have a pair of macros to add a new weapon to the object and everything is almost working, but when I run the macro two things occur:
1) The macro, instead of assigning the result to the Weapons property already present on the token, creates a new invisible property and assigns it to that.
2) The macro assigns the default weapon information correctly, but fails to add the new weapon's information.
Expected result:
The macro adds the default weapon ("Unarmed") if the property is empty, then adds the new weapon's information to the property already present on the token
The first macro (present in the Campaign macro set):
Spoiler
Code: Select all
<!-- Take input from the user to add a weapon to the selected character using the AddWeapons library macro
-->
[h: wEntry = "{}"]
[h: newName = ""]
[h: newDamage = 0]
[h: newBonus = 0]
[h: newVariables = "{}"]
[h: newAutoDmg = "{}"]
[h: newAuto = 0]
[h: input(
"newName|''|Enter a name for the new weapon|TEXT",
"newLevel|0|Enter a level for the new weapon|TEXT",
"newAttack|0|Enter an attack bonus for the new weapon|TEXT",
"newVariables|''|Enter variables of the weapon, sepperated by commas and no spaces|TEXT",
"newAutoBool|1|Does this weapon automatically deal ACV?|CHECK",
"newAuto|0|Enter automatic damage of the weapon|TEXT"
)]
[h: wEntry = json.set(wEntry, "newName", newName)]
[h: wEntry = json.set(wEntry, "newLevel", newLevel)]
[h: wEntry = json.set(wEntry, "newAttack", newAttack)]
[h: wVarArr = json.fromList(newVariables)]
[h: wEntry = json.set(wEntry, "newVariables", wVarArr)]
[h, if(newAutoBool == 1), code: {
[h: newAutoDmg = json.set(newAutoDmg, "1", "AttackCombatValue")]
};
{[h: newAutoDmg = json.set(newAutoDmg, "1", "None")]}
]
[h: newAutoDmg = json.set(newAutoDmg, "2", newAuto)]
[h: wEntry = json.set(wEntry, "newAuto", newAutoDmg)]
[h, macro("NewWeapon@Lib:CharacterCreation"): wEntry]
Spoiler
Code: Select all
<!-- initialize variables to use for weapon creation.
weaponEntry is used to combine the objects into one entry in the property
weaponProps is used to store all of the properties of the weapon together
weaponVariables is used to store the different variables of a weapon as a nested object
weaponAutoDmg is used to sepparate the ACV value, if present, from bonus damage
-->
[h:weaponEntry = "{}"]
[h:weaponProps = "{}"]
[h:weaponVariables = "{}"]
[h:weaponAutoDmg = "{}"]
<!-- if the Weapons property is empty, create a new object as its value and create an unarmed attack as the default value -->
[h, if(json.isEmpty(Weapons)), code: {
[h: weaponProps = json.set(weaponProps, "Level", 0)]
[h: weaponProps = json.set(weaponProps, "Attack", 0)]
[h: weaponVariables = json.set(weaponVariables, "1", "stun")]
[h: weaponVariables = json.set(weaponVariables, "2", "nonpenetrating")]
[h: weaponProps = json.set(weaponProps, "Variables", weaponVariables)]
[h: weaponAutoDmg = json.set(weaponAutoDmg, "1", "AttackCombatValue")]
[h: weaponAutoDmg = json.set(weaponAutoDmg, "2", 0)]
[h: weaponProps = json.set(weaponProps, "AutoDmg", weaponAutoDmg)]
[h: weaponEntry = json.set(weaponEntry, "Unarmed", weaponProps)]
[h: setProperty(Weapons, weaponEntry)]
};{}]
<!-- retrieve the individual entries from the calling macro -->
[h: wName = json.get(macro.args, "newName")]
[h: wLevel = json.get(macro.args, "newLevel")]
[h: wAttack = json.get(macro.args, "newAttack")]
[h: wVariables = json.get(macro.args, "newVariables")]
[h: wAutoDmg = json.get(macro.args, "newAuto")]
<!-- create a new object to append to the property -->
[h: weaponProps = json.set(weaponProps, "Level", wLevel)]
[h: weaponProps = json.set(weaponProps, "Attack", wAttack)]
[h: weaponProps = json.set(weaponProps, "Variables", wVariables)]
[h: weaponProps = json.set(weaponProps, "AutoDmg", wAutoDmg)]
<!-- append the new weapon to the Weapon property -->
[h: wList = "{}"]
[h: wList = getProperty(Weapons)]
[h: json.set(wList, wName, weaponProps)]
[h: setProperty(Weapons, wList)]