# Is it possible to combine multiple outputs in AnyDice?

I have a situation where I will be making four attacks that do different amounts of damage over the course of a round. I have the average damage of each of them(including the likelihood of missing with the attack) modelled as a separate output on AnyDice, using a modified function I found through this youtube video but I'm wondering if I can make a fifth output that models the average damage for the entire round.

https://anydice.com/program/2fb41 <- what I have so far

\the first attack is a guaranteed critical hit due to some time shenanigans, so no chance of getting 0 damage\

output 8d6 + 2d8 + 5 named "First Attack"

function: attackroll ROLL:n vs AC:n {
if ROLL >= CRITROLL { result: CRITDAMAGE }
if ROLL = 1 { result: 0 }
if ROLL + PROFICIENCY + ATTACKMOD >= AC { result: DAMAGE }
result: 0
}

ENEMYAC: 14

ATTACKMOD: 5
PROFICIENCY: 3
CRITROLL: 20
DAMAGE: 1d6 + ATTACKMOD
CRITDAMAGE: 2d6 + ATTACKMOD
output [attackroll d20 vs ENEMYAC] named "Offhand Attack"

ATTACKMOD: 5
PROFICIENCY: 3
CRITROLL: 20
DAMAGE: 4d6 + 1d8 + ATTACKMOD
CRITDAMAGE: 4d6 + 2d8 + ATTACKMOD
output [attackroll d20 vs ENEMYAC] named "Attack of Opportunity"

output 2d8 named "Booming Blade damage if he lives long enough to move"


### Yes, just save the outputs in variables and sum them:

FIRST: 8d6 + 2d8 + 5
output FIRST named "First Attack"

\ ... some code omitted ... \
OFFHAND: [attackroll d20 vs ENEMYAC]
output OFFHAND named "Offhand Attack"

\ ... some code omitted ... \
OPPORTUNITY: [attackroll d20 vs ENEMYAC]
output OPPORTUNITY named "Attack of Opportunity"

BOOMING: 2d8
output BOOMING named "Booming Blade damage if he lives long enough to move"

TOTAL: FIRST + OFFHAND + OPPORTUNITY + BOOMING
output TOTAL named "Total damage from all the attacks"


There's nothing special about output statements in AnyDice: anything you can plot with output you can also assign to a global variable to be plotted (or used for any other purpose) later.

## Yes

But you can't rely on global variables in your functions. You need to add those as parameters to each function and call them with the right values. I'll show you the first and leave the rest as an exercise:

function: attackroll ROLL:n plus PROFICIENCY:n plus ATTACKMOD:n vs AC:n for
DAMAGE:d or CRITDAMAGE:d on CRITROLL:n {
if ROLL >= CRITROLL { result: CRITDAMAGE }
if ROLL = 1 { result: 0 }
if ROLL + PROFICIENCY + ATTACKMOD >= AC { result: DAMAGE }
result: 0
}

output [attackroll d20 plus 3 plus 5 vs 14 for (1d6+5) or (2d6+5) on 20] named "Offhand Attack"


You can then add as many of these together as you like (or as many as anydice will deal with).