Having trouble with count() in macro.

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

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

Post Reply
Rebullet
Kobold
Posts: 14
Joined: Wed Jun 24, 2020 11:51 am

Having trouble with count() in macro.

Post by Rebullet »

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.","")] 

}]

User avatar
aliasmask
Deity
Posts: 8579
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Having trouble with count() in macro.

Post by aliasmask »

Do you get an error message? The most likely cause is one of your values is not an actual value, like possibly for this line

Code: Select all

[h: penetration = armor - getProperty("Weapon1Penetration")]
If Weapon1Penetration is blank, rather than 0, then it would cause an error.


edit: Another issue could be the eval. If the variable is a number, eval will blow up. I suggest using eval(string(...)), just in case.

Rebullet
Kobold
Posts: 14
Joined: Wed Jun 24, 2020 11:51 am

Re: Having trouble with count() in macro.

Post by Rebullet »

it works exactly as i wish without the count() and i made sure that the values were filled. so im really confused as to what is happening.


Rebullet
Kobold
Posts: 14
Joined: Wed Jun 24, 2020 11:51 am

Re: Having trouble with count() in macro.

Post by Rebullet »

it just outputs the code i was using from this point on.

[h,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)] The 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.","")] }]

User avatar
aliasmask
Deity
Posts: 8579
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Having trouble with count() in macro.

Post by aliasmask »

Try replacing {getProperty("Weapon1")} with [r: getProperty("Weapon1")] and see what happens.

Rebullet
Kobold
Posts: 14
Joined: Wed Jun 24, 2020 11:51 am

Re: Having trouble with count() in macro.

Post by Rebullet »

So yea i have put it as such now. same result.

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: damageType = getProperty("Weapon1DamageType")]
[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: armor = 0]

<!-- process -->
[h:switchToken(currentT)]

[h,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  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.","")]
}]

User avatar
wolph42
Deity
Posts: 9707
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: Having trouble with count() in macro.

Post by wolph42 »

adding the error reports really help to recognize the issue!
to target's
there's your problem. Remove the apostrophe ' (and any others that still might be there)

It's a bit FU but single ' break code blocks when they're not [h:" 'sealed' "] or 'closed', so either make darn sure there are two in one line of text or use " or seal them in two " inside a [ ]. The funny thing is that you can omit the code level limitation is you end your code blocks with two '', so its a gift and a curse.

http://lmwcs.com/rptools/wiki/Introduct ... postrophes

User avatar
aliasmask
Deity
Posts: 8579
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Having trouble with count() in macro.

Post by aliasmask »

Yeah, I suspected that, but I was pretty sure you could use ' in chat. The thing I'm realizing now is if in a code block, the parser will consider everything after the ' as a string, including the closing braces. That seems to be a bug. Still works if outside of a code block.

Rebullet
Kobold
Posts: 14
Joined: Wed Jun 24, 2020 11:51 am

Re: Having trouble with count() in macro.

Post by Rebullet »

that was it thank you my dudes. now i can continue to stumble through these macros. lolz.

Post Reply

Return to “Macros”