You're slightly wrong about what's wrong
But it's slightly Anydice's fault. It doesn't have good debugging tools. The specific issue Anydice has here is that you're trying to compare a die to a value. Or to anything, really. The die in question is COUNT
. Now, COUNT
a die because it is generated from another die. It also happens to be d{0}
, so it doesn't even begin to have the information you're looking for.
But I think the full solution starts even before that. I assume you're casting to a die and using [maximum of N]
so you can dynamically have the function find N for you. Except it doesn't work like that for multiple dice. Specifically, Anydice combines 2d12 into a single die with the equivalent distribution. So the [maximum of 2d12]
is 24. As a bit of an aside, the built in explode
does use maximum
, but it also doesn't explode quite the way you want. It explodes when you roll max for the roll (=the max sum). You can see the difference between [explode 2d12]
and 2[explode 1d12]
.
And after you've tried to find the die size, you're using the pool as though it were a sequence even though you cast it to a die. A key thing to remember with Anydice is that if you want to do complicated introspection on a die pool, you need to cast it to a sequence.
So to the solution. First, let's give up trying to just find N, we know what input we're giving, so we can just also give it that number. Then, since we want to do introspection stuff we cast it to a sequence. That means things like count
work the way we expect it to. Then you assume we want to compare and roll against the COUNT
target of P
, so let's just do that more dynamically. Of note, when we roll another dN we need to generate it to be a normal die: d{1..N}
. Since we're just looking for the greater than chance, we can have return that. If you wanted to do more complicated conditionals with the new die, you'll probably have to pass it to a helper function, and you need to pass it before you try to compare it.
function: explode DIE:s on N:n target P:s {
COUNT: [count N in DIE]
if COUNT > 0 {result: d{1..N} > COUNT@P}
result:0
}
output [explode 2d12 on 12 target {7, 4}]
Oh, and if you want to disentangle the size of the "explode" critera to the size of the new die, you'll probably have to set up a new parameter (or hard-code it I suppose).
d{N}
will give you a uniform roll across all possible values of the dice expressionN
.dN
will give you the expected distribution of that dice roll expression. For example, ifN: 4d12
, you'll get a flat distribution from 4 to 48. This likely isn't what you want, though it doesn't seem to solve your question. \$\endgroup\$d{EXTREME}
? \$\endgroup\${}
unnecessarily as those establish a new dice kind. For exampled{1,4,7}
is a three-sided die with faces 1, 4, and 7.d{2d6}
is an 11-sided die with faces 2 through 12. \$\endgroup\$dEXTREME
is equivalent to1d12
where asd{EXTREME}
is a 1-sided die whose only face is 12. \$\endgroup\$1@P
supposed to be2@P
in theCOUNT = 2
block? Otherwise, you're not actually doing anything different between the two count results. \$\endgroup\$