Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

Calculation based on roll result within the same roll button

I'm working on a roll template and I'd like it to show both the number of successes and the number of failures (pools of d6s: 6s are successes). So I've got the roll button calculating the dice pool, rolling the dice and counting the successes, and I've got the roll template displaying the result. I've also put in an extra calculation for the total number of dice being rolled, so I can get the roll template to display both the number of success {{result}} and the total number of dice that were rolled {{total}} . Which is fine, but purely for taste I'd prefer to have the number of failures instead of the total. As roll templates cannot do any calculations themselves I can't just tell it {{result}} - {{total}} . So I would have to put this calculation in the roll button code. But can the roll button do this at the same time as rolling the dice?
1599408713
GiGs
Pro
Sheet Author
API Scripter
A few months ago, the answer would be no - you cant do this with a roll macro. But we recently discovered the Reusing Roll trick so it is possible, if clunky. If you post what a typical roll value sent to this rolltemplate looks like, we can tell you how to write it, but as a default template, it would look something like this: &{template:default} [[ ?{NumberDice|1} - [[?{NumberDice}d6>6]] ]] {{successes=$[[0]]}} {{failures=$[[1]]}} Then you can use the successes and failures  values in your rolltemplate code. Note the actual roll is not inside {{ }} brackets.
1599408810

Edited 1599409002
Kavini
Pro
Marketplace Creator
Sheet Author
Compendium Curator
Roll templates can't make any calculations, only display the results of calculations from rolls. It's impossible to make the sort of roll you want, except in a slightly hacky way. So, while you can't make that calculation, you can use the roll template to compare one number to another. So, if you're working with a fairly limited dice pool, it's trivial to generate a dynamic response. Imagine (for the sake of brevity) that your dice pool is only 3 dice. You could write something like this: {{#rollTotal() total 1}} // if we rolled one dice then... {{#rollTotal result 0}} // ...a result of 0 must mean 1 failure 1 failure {{/rollTotal result 0}} {{#rollTotal() result 1}} // ...a result of 1 must mean 0 failures 0 failures {{/rollTotal() result 1}} {{/rollTotal() total 1}} {{#rollTotal() total 2}} // if we rolled two dice then... {{#rollTotal result 0}} // ...a result of 0 must mean 2 failures 2 failures {{/rollTotal result 0}} {{#rollTotal() result 1}} // ...a result of 1 must mean 1 failure 1 failure {{/rollTotal() result 1}} {{#rollTotal() result 2}} // ...a result of 2 must mean 0 failures 0 failures {{/rollTotal() result 2}} {{/rollTotal() total 2}} {{#rollTotal() total 3}} // etc. etc. {{#rollTotal result 0}} 3 failures {{/rollTotal result 0}} {{#rollTotal() result 1}} 2 failures {{/rollTotal() result 1}} {{#rollTotal() result 2}} 1 failure {{/rollTotal() result 2}} {{#rollTotal() result 3}} 0 failures {{/rollTotal() result 3}} {{/rollTotal() total 3}} And, as I'm sure you can imagine, this is a massive pain to manually write and test for large number sets, which is really why most people wouldn't do it. That said, if you use a HTML pre-processor like PUG, it becomes much easier to achieve via looping. EDIT: Huh, GiGs, TIL.
Thanks GiGs. An example would be: &{template:xxx} {{successes=[[([[{[[@{res}+?{Bonus dice|0}]],1}kh1]])d6>6]]}} {{total=[[@{res}+?{Bonus dice|0}]]}} So the Reusing Roll trick would make it look like this? &{template:xxx} [[ [[@{res}+?{Bonus dice|0}]] - [[([[{[[@{res}+?{Bonus dice|0}]],1}kh1]])d6>6]] ]] {{successes=$[[0]]}} {{failures=$[[1]]}}
1599449926
GiGs
Pro
Sheet Author
API Scripter
Almost! since you added some extra inline rolls that changes the numbers needed in the $[[ ]] sections. To cut down on the number of inline rolls, I would streamline  your successes rolls to {{successes=[[ [[{@{res}+?{Bonus dice|0},1}kh1]]d6>4]]}} Since there are 2 inline rolls here, you grab this value with $[[1]] So your rolltemplate would look like {template:xxx} [[ @{res}+?{Bonus dice|0} - [[ [[{@{res}+?{Bonus dice|0},1}kh1]]d6>4]] ]] {{successes=$[[1]]}} {{failures=$[[2]]}} I also removed the other inline brackets around the total calculation. We dont need that as a separate roll, so no need to calculate it.
Fantastic! Thanks GiGs, very much appreciated.
1599496901
GiGs
Pro
Sheet Author
API Scripter
You're welcome :)