If Roll Option Error help

Discuss macro implementations, ask for macro help (to share your creations, see User Creations, probably either Campaign Frameworks or Drop-in Resources).

Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice

Post Reply
ecclektik
Kobold
Posts: 17
Joined: Thu Dec 12, 2019 11:50 pm

If Roll Option Error help

Post by ecclektik »

Edit: I think I resolved my original error but am now getting an error message I can't decipher. I edited this for the new message.

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)]
		}]
}]

ecclektik
Kobold
Posts: 17
Joined: Thu Dec 12, 2019 11:50 pm

Re: If Roll Option Error help

Post by ecclektik »

I figured it out. Apparently the json.path.read returns a json array of the value(s), not the value(s) which was not clear from the wiki entry. The logical operators were trying evaluate an array being equal to an integer which was the error. I performed a json.get on index zero on the result of the json.path.read and it works perfect now. That is what I am also going to do to extract each weapon parameter value and copy it to the token property.

Post Reply

Return to “Macros”