So what should your function look like? Something like this (modulo a misreading of the question; see correction below), for example:
(BTW, you might be wondering what happens if you call the function above with 1d4
, so that ROLL
has only one element. In fact, it still works, though only by a bit of a coincidence. What happens in that case is that 2@ROLL
evaluates to 0, since that what AnyDice gives you if you ask for an element past the end of a sequence. And since d4
is always higher than 0, the function just ends up rerolling the single die if it's originally a 1.)
Correction: When writing the answer above, I completely missed the latter part of the "the highest die is rerolled if it's a 3 or a 4" rule, so the code above doesn't implement it. We can fix it easily, though:
function: test ROLL:s {
if !(ROLL = 1 & 1@ROLL = {3,4}) { result: 1@ROLL }
result: [highest of d4 and 2@ROLL]
}
This version runs the { result: 1@ROLL }
block unless the roll contains any ones and the first (i.e. highest) number in the roll is 3 or 4.
(1@ROLL = {3,4}
is a fairly literal translation of the "it's a 3 or a 4" rule. Of course we could've euivalently written it e.g. as 1@ROLL >= 3
or even — since having any number in the roll ≥ 3 is equivalent to the highest number being ≥ 3 — as ROLL >= 3
. We can't write it as ROLL = {3,4}
, though; that's a sequence-to-sequence comparison, and those work differently.)