3
\$\begingroup\$

I've just discovered AnyDice and I'm trying to use it to model a simple problem and failing miserably. That usually means there is some basic concept I'm not understanding.

First, the problem. I just want to look at a simple hits-and-saves game mechanic. My super-weapon has a ROF of 5. So I throw 5 d6, and hit on a 5 or 6. Their super-armour saves on 6. How hard is it to kill them? I roll 5 d6, get x hits then they roll x d6 and get y wounds. What does the wound probability look like for weapons with different ROFs, and armour with different saves?

The to-hit roll I understand how to do:

function: hitme NN:n
{
   result: [count {5, 6} in NN d6]
}

output [hitme 5]

But what I don't understand is how to concatenate this with the next dice roll. I would have expected, in a dice rolling program, some data structure that represented the probability results of a roll, which would then be an input to the next roll simulation.

In other words, I'm expecting to be able to do something like this pseudo-code:

function rollme(dice) : return outcome-probability 
function saveme(outcome-probability, dice) : return final outcome-probability

Clearly my expectation of how this should work is wrong. I see "dice" which I understand to be the shape of the dice not the rolled results, "sequence", and "number". Is "result:" um... the result... and how do I pass it in to the save-roll function that I imagine I have to write next, and have the probabilities combined correctly?

\$\endgroup\$
1
  • \$\begingroup\$ You might also try math.stackexchange.com to understand the math behind the program better. \$\endgroup\$
    – Jim B
    Commented Sep 21, 2015 at 2:04

1 Answer 1

2
\$\begingroup\$

To input the result of a function into another function, simply call the second function with the first function as a parameter.

For example, your complete AnyDice program could look like this:

function: hitme NN:n {
  result: [count {5, 6} in NN d6]
}

function: woundme HH:n {
result: [count {1, 2, 3, 4, 5} in HH d6]
}

output [woundme [hitme 5]]
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .