Having trouble with count() in macro.
Posted: Wed Jun 24, 2020 11:56 am
Im having a lot of trouble getting this loop to work even though it is following my prior loop logic, which works. so i must be missing something. the problem area is right after the <!-- process --> comment i have when the count loop starts. thats where it breaks.
Code: Select all
<!-- get -->
[h: weaponName = getProperty("Weapon1")]
[H: tokenList = getExposedTokenNames()]
[h: currentT = listGet(tokenList, 0)]
[h: tokenList = listDelete(tokenlist, 0)]
[H: imgList = tokenList]
[H: Num = listCount(imgList)]
[h,COUNT(Num),CODE:
{
[h:tokenName=listGet(imgList,roll.count)]
[h,token(tokenName): image=getTokenImage()]
[h:imgList=listReplace(imgList,roll.count,tokenName+" "+image)]
}]
[h:status=input(
"targetNum|"+imgList+"|Select Target|LIST|SELECT=0 ICON=TRUE ICONSIZE=60",
"hits|0,1,2,3,4,5,6,7,8,9,10|Select Number of Hits|LIST|SELECT=0"
)]
[h:abort(status)]
[h:targetName = listGet(tokenList,targetNum)]
[h: hitsList = "1,2,3,4,5,6,7,8,9,10"]
[h: numberOfHits = listGet(hitsList,hits)]
[h:switchToken(targetName)]
[h:armorHead = getProperty("ArmorHead")]
[h:armorRightArm = getProperty("ArmorRightArm")]
[h:armorLeftArm = getProperty("ArmorLeftArm")]
[h:armorBody = getProperty("ArmorBody")]
[h:armorRightLeg = getProperty("ArmorRightLeg")]
[h:armorLeftLeg = getProperty("ArmorLeftLeg")]
[h: TB = getProperty("TB Reduction")]
[h: damageType = getProperty("Weapon1DamageType")]
[h: armor = 0]
<!-- process -->
[h:switchToken(currentT)]
[count(numberOfHits), code:
{
[h: hitLocation = 1d100]
[h: armor = if(hitLocation >= 1 && hitLocation <= 10, armorHead, armor)]
[h: armor = if(hitLocation >= 11 && hitLocation <= 20, armorRightArm, armor)]
[h: armor = if(hitLocation >= 21 && hitLocation <= 30, armorLeftArm, armor)]
[h: armor = if(hitLocation >= 31 && hitLocation <= 70, armorBody, armor)]
[h: armor = if(hitLocation >= 71 && hitLocation <= 85, armorRightLeg, armor)]
[h: armor = if(hitLocation >= 86 && hitLocation <= 100, armorLeftLeg, armor)]
[h: penetration = armor - getProperty("Weapon1Penetration")]
[h: damageByWeapon = eval(getProperty("Weapon1Damage"))]
[h: remainingArmor = if(penetration > 0, penetration, 0)]
<!-- output -->
The {getProperty("Weapon1")} deals
[r: damageByWeapon - (remainingArmor + toughness)] [r: damageType] to target's
[r: if((hitLocation >= 1 && hitLocation <= 10),"head.","")]
[r: if((hitLocation >= 11 && hitLocation <= 20),"right arm.","")]
[r: if((hitLocation >= 21 && hitLocation <= 30),"left arm.","")]
[r: if((hitLocation >= 31 && hitLocation <= 70),"body.","")]
[r: if((hitLocation >= 71 && hitLocation <= 85),"right leg.","")]
[r: if((hitLocation >= 86 && hitLocation <= 100),"left leg.","")]
}]