listContains() not getting correct results from getRolled() list

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
Rebullet
Kobold
Posts: 14
Joined: Wed Jun 24, 2020 11:51 am

listContains() not getting correct results from getRolled() list

Post by Rebullet »

im having trouble with listContains getting the correct number of values out of a getRolled() list. it works for a higher volume of dice but only some of the time which confounds me.

Code: Select all

[COUNT(numberOfHits, ""),CODE:
{
<br>
[h: didCrit = 0]
[h: hitLocation = 1d100]
[h: critDamage = ""]

[h:switchToken(targetName)]

[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: clearRolls()]
[h: penetration = armor - weaponPen]

[h:switchToken(currentT)]

[h: damageByWeapon = eval(getProperty("Weapon1Damage"))]
[r: rollList = getRolled()]
[r: listContains(rollList, 10)]
[r: didCrit = if(listContains(getRolled(), 10) > 0, 1, didCrit)]
[h: remainingArmor = if(penetration > 0, penetration, 0)]

<!-- output -->
[h:switchToken(targetName)]
[r: "The "]
[r: weaponName]
[r: " deals "]
<b><font color="blue">[r: damageByWeapon - (remainingArmor + TB)]</color></b>
[r: " "]
<b><font color="green">[r: damageType]</color></b>
[r: " 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.","")]

[h: critPreText = "Sadly, there was no Righteous Fury"]
[h: critPostText = " in this attack."]

[h, if(didCrit == true), code:
{
	[h: critDamage = roll(1, 5)]
	[h: critPreText = "The " + weaponName + " also deals "]
	[h: critPostText = " critical " + damageType + " to target's "]
	[h: critPostText = if((hitLocation >= 1 && hitLocation <= 10), critPostText + "head.",critPostText)]
	[h: critPostText = if((hitLocation >= 11 && hitLocation <= 20), critPostText + "right arm.",critPostText)]
	[h: critPostText = if((hitLocation >= 21 && hitLocation <= 30), critPostText + "left arm.",critPostText)]
	[h: critPostText = if((hitLocation >= 31 && hitLocation <= 70), critPostText + "body.",critPostText)]
	[h: critPostText = if((hitLocation >= 71 && hitLocation <= 85), critPostText + "right leg.",critPostText)]
	[h: critPostText = if((hitLocation >= 86 && hitLocation <= 100), critPostText + "left leg.",critPostText)]
};{""}]
<br>
[r: critPreText]
<b><font color="red">[r: critDamage]</color></b>
[r: critPostText]

}]
i get results like this: [10,6] 0 0 The Chainsword deals 18 Rending Damage to target's left leg. Sadly, there was no Righteous Fury in this attack.

the first few numbers before the sentence are just giving me a view as to what is being seen.

[10, 6] = numbers rolled on 2d10
first 0 = number of 10's in the list
second 0 = should be one if there are any 10's in the list.

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

Re: listContains() not getting correct results from getRolled() list

Post by Rebullet »

so apparently the ends of the list are not looked at. [10, 0, 10] will fail but [0, 10, 0] will succeed. i have no idea why.

taustinoc
Dragon
Posts: 518
Joined: Mon Aug 03, 2015 6:30 pm

Re: listContains() not getting correct results from getRolled() list

Post by taustinoc »

The obvious workaround for that would be to add on "0," at the beginning and ",0" at the end before checking.

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: listContains() not getting correct results from getRolled() list

Post by wolph42 »

im surprised this works at all. [1,2,3] is an array and "1,2,3" is a list. either turn the json array into a list Wiki: json.toList() or use Wiki: json.count()
edit:
ah wait its actually "[1,2,3]" so the 'list' is [1 and 2 and 3] so the only number in there is '2'.

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

Re: listContains() not getting correct results from getRolled() list

Post by Rebullet »

wolph42 wrote:
Thu Jun 25, 2020 6:06 pm
im surprised this works at all. [1,2,3] is an array and "1,2,3" is a list. either turn the json array into a list Wiki: json.toList() or use Wiki: json.count()
edit:
ah wait its actually "[1,2,3]" so the 'list' is [1 and 2 and 3] so the only number in there is '2'.
yea that was it. didnt realize it was an array rather than a list.

Post Reply

Return to “Macros”