# How do I check the lowest roll in a pool of mixed dice in Anydice?

I'm trying to build a function to model not just a roll of the dice, but to have boolean operators to toggle using various powers that effect the dice. I've gotten everything to work except for one thing; looking at the result of the roll, seeing if a '1' was rolled and then changing that '1', but only once.

The dice mechanic is for Cryptomancer, and it works by taking your rank in a skill which is 1 to 5 and rolling that many d10's plus a number of d6's that total to 5 dice. For d10s, 1's are always botches (-1), numbers under the target number are 0's and numbers equal to or greater the target are successes (+1). On the d6's 1s are botches, 6s are success and everything else is 0.

I've been using custom die for my rolls, but set the function up to build the roll off just a skill number and challenge number. Here's what I got so far:

function: sb B:n sp P:n skill SKILL:n vs CHALLENGE:n{
if P=1{
ROLL: SKILLd{-1,0:(CHALLENGE-2),1:(10-CHALLENGE),2}+(5-SKILL)d{-1,0:4,1}
}
else {
ROLL: SKILLd{-1,0:(CHALLENGE-2),1:(11-CHALLENGE)}+(5-SKILL)d{-1,0:4,1}
}
if B=1{
if 5@ROLL=-1{
ROLL:ROLL+2
}
}
result:ROLL
}


The goal is that you can toggle things by entering a 1 or 0 for the values B and P to turn them on or off. P=1 makes all '10s' rolled be worth +2 success instead of +1. B=1 is suppose to check the last value of the roll, and if a -1 is present add 2 to the whole total, there by turning one and only one botch into a success, even if there are multiple botches in the roll.

Everything works till I turn on B. then I get an error that the boolean operation if can only be used on numbers. Turns out 5@ROLL isn't giving me the lowest roll of 5 dice but the probability of what that roll will be. How do I fix this? How can I convert ROLL:d into ROLL:s?

• Welcome to RPG.SE! Take the tour if you haven't already and see the help center or ask us here in the comments (use @ to ping someone) if you need more guidance. Good Luck and Happy Gaming! – Someone_Evil Jul 5 at 20:03

# Use a subfunction to do test for certain rolls

In order to do tests like "Is there a -1 rolled in this pool" you need to cast the dice pool to a function to make it a sequence (AnyDice will then run the function for each possible sequence). The problem is that when you sum dice it becomes a number and we need it to be dice (so we can cast it to a sequence).

Solution? Don't combine until you have to. Store the d10 and d6 pools as seperate variables and pass them both to a subfunction. That subfunction tests if the last roll in either pool is -1 and if it is returns the roll total +2, otherwise it returns just the roll total. My AnyDice code:

function: sbcheck A:s B:s{
if (#A)@A = -1 | (#B)@B = -1 {
result: A+ B+ 2
}
else {result:A+B}
}

function: sb B:n sp P:n skill SKILL:n vs CHALLENGE:n{
if P=1{
TENPOOL: SKILLd{-1,0:(CHALLENGE-2),1:(10-CHALLENGE),2}
}
else {
TENPOOL: SKILLd{-1,0:(CHALLENGE-2),1:(11-CHALLENGE)}
}
SIXPOOL: (5-SKILL)d{-1,0:4,1}
if B=1{
result: [sbcheck TENPOOL SIXPOOL]
}
result:TENPOOL+SIXPOOL
}
output [sb 0 sp 1 skill 3 vs 4]
output [sb 1 sp 1 skill 3 vs 4]

• Thank you very much! I figured a sub function would be needed, but I didn't realize adding the pools together would also complicate things. – horomancer Jul 5 at 23:06