After finishing the macro to populate weapons into a library token and then the macro to add weapons from the library to the token's inventory, I am continuing on with a macro to equip a weapon from one of the ones in the token inventory. I have the token set up with a main hand and an off hand and a weapon can be equipped into either. I am also setting this up to check if a 2 handed weapon is equipped in either slot and produce a message if so, without equipping.
I am getting the following error:
Illegal argument type com.google.gson.JsonArray, expecting java.math.BigDecimal or java.lang.String
The macro is partially completing in that the Property "MainWeapon" or "OffWeapon" are updated with the weapon object but all the associated properties are not being updated with the FOREACH loop.
The code follows:
Code: Select all
[h: abort(isOwner())]
<!-- Gets Current inventory and equipped weapons -->
[h: WeaponInventory = getProperty("WeaponInventory")]
[h: MainWeapon = getProperty("MainWeapon")]
[h: OffWeapon = getProperty("OffWeapon")]
<!-- Creates selection list, adding None to end of the list to unequip -->
[h: WeaponsList = listSort(json.toList(json.path.read(WeaponInventory,strformat(".Name"))),"A")]
[h: None = json.set("{}","Name","None","SRange",0,"MRange",0,"LRange",0,"NumDMG",0,"DMGDie",0,"DMGMod",0,"AP",0,"RoF",0,"MaxShots",0,"MinStr",0,"WT",0,"Cost",0,"Parry",0,"Hand",1)]
[h: WeaponsList = listAppend(WeaponsList,"None")]
[h: abort(input("NewWeapon|"+WeaponsList+"|Select New Weapon|LIST|SELECT=0 VALUE=STRING","Hand|Main,Offhand|Select Which Hand|LIST|SELECT=0 VALUE=STRING"))]
<!-- If None is selected, sets the weapon to empty object -->
[h, switch(Hand), code:
case "Main": {
[h, if(NewWeapon=="None"), code:
{
[h: MainWeapon = None]
};
{
[h: MainWeapon = json.path.read(WeaponInventory,strformat(".[?(@.Name == '%{NewWeapon}')]"))]
}]
};
case "Offhand": {
[h, if(NewWeapon=="None"), code:
{
[h: OffWeapon = None]
};
{
[h: OffWeapon = json.path.read(WeaponInventory,strformat(".[?(@.Name == '%{NewWeapon}')]"))]
}]
}]
<!-- Determines how many hands each weapon requires and produces an error message-->
[r: MainHands = json.path.read(MainWeapon,".Hand")]
[r: OffHands = json.path.read(OffWeapon,".Hand")]
[r: assert(OffHands==2 && MainHands==2,"You cannot have a 2-handed weapon equipped in each hand.")]
<!-- Sets the property with the newly selected weapons -->
[h, switch(Hand), code:
case "Main": {
[h: setProperty("MainWeapon",MainWeapon)]
[h: Stats = json.toVars(MainWeapon,"M")]
[h, FOREACH(Stat,Stats), code:
{
[r: StatName = Stat]
[r: StatVal = eval(Stat)]
[h: setProperty(StatName,StatVal)]
}]
};
case "Offhand": {
[h: setProperty("OffWeapon",OffWeapon)]
[h: Stats = json.toVars(OffWeapon,"M")]
[h, FOREACH(Stat,Stats), code:
{
[r: StatName = Stat]
[r: StatVal = eval(Stat)]
[h: setProperty(StatName,StatVal)]
}]
}]