Character Vault
Any Concept / Any System
Compendium
Your System Come To Life
Roll20 for Android
Streamlined for your Tablet
Roll20 for iPad
Streamlined for your Tablet

Personal tools

Difference between revisions of "Reusing Rolls"

From Roll20 Wiki

Jump to: navigation, search
m (add macro guide navbar)
(New section: Toggleable template fields, an update on reusing rolls)
 
(19 intermediate revisions by 5 users not shown)
Line 1: Line 1:
In early 2020, it was noticed that you could re-use roll in macros without using API. This Page lists some of the top posts and comments that figures out uses for it.{{NavMacroDocs}}
+
{{revdate}}In early 2020, it was noticed that you could re-use roll in [[macros]] without using [[API]]. This page lists some of the top posts and comments that figures out uses for it.
  
 
* {{forum|permalink/9091992/ Reusing Rolls - Megathread}}
 
* {{forum|permalink/9091992/ Reusing Rolls - Megathread}}
 
* {{forum|post/9161706/re-use-die-rolls-in-macros-treated-as-numbers-rather-than-just-text Re-use die rolls in macros, treated as numbers rather than just text}} - Suggestion Forums
 
* {{forum|post/9161706/re-use-die-rolls-in-macros-treated-as-numbers-rather-than-just-text Re-use die rolls in macros, treated as numbers rather than just text}} - Suggestion Forums
 +
{{NavMacroDocs}}
 
* {{forum|permalink/8716289/ Original discovery}} by Syneran
 
* {{forum|permalink/8716289/ Original discovery}} by Syneran
 
<br>
 
<br>
==Collected tricks==
+
==Collected Tricks==
===Scott C's Trick===
+
===Scott C's Original Trick===
 
{{forum|permalink/8747581/ Stupid Roll20 Tricks (and some clever ones)}} - Initial Trick writeup - [[Scott|Scott C]]
 
{{forum|permalink/8747581/ Stupid Roll20 Tricks (and some clever ones)}} - Initial Trick writeup - [[Scott|Scott C]]
  
*Disclaimer: This trick takes advantage of emergent behavior that may not be intended and may be patched*
+
'''Disclaimer: This trick takes advantage of emergent behavior that may not be intended and may be patched'''
  
 
I can't take credit for this trick. Syneran discovered the capability. But, long story short, it is actually possible to reuse rolls with some small caveats. Here's a summary of the info discovered in the linked forum thread:
 
I can't take credit for this trick. Syneran discovered the capability. But, long story short, it is actually possible to reuse rolls with some small caveats. Here's a summary of the info discovered in the linked forum thread:
  
The chat accepts the inline roll indexing used in the API (and apparently the roll parser itself), so you can do:
+
The chat accepts the [[Inline Rolls|inline roll]] indexing used in the [[API]] (and apparently the roll parser itself), so you can do:
<pre>
+
<pre style="overflow:hidden;white-space:pre-wrap">
 
[[ [[1d20]] + [[1d6]] + [[6]] ]] = $[[0]] + $[[1]] + $[[2]]
 
[[ [[1d20]] + [[1d6]] + [[6]] ]] = $[[0]] + $[[1]] + $[[2]]
 
</pre>
 
</pre>
And get an output that would read something like this:
+
And get an output that would read like this:
  
(image todo)
+
[[File:Reuse-rolls-ex1.png]]
  
The limited part is you can't use those indexed rolls inside other rolls. So for instance, you can't reverse the above output like this:
+
The limited part is you can't use those indexed rolls inside other rolls. So for instance, you '''cannot''' reverse the above output in the following way:
 
+
<pre style="overflow:hidden;white-space:pre-wrap">
<pre>
+
 
[[1d20]] + [[1d6]] + [[6]] = [[$[[0]] + $[[1]] + $[[2]] ]]
 
[[1d20]] + [[1d6]] + [[6]] = [[$[[0]] + $[[1]] + $[[2]] ]]
 
</pre>
 
</pre>
 +
Using the indexes appears to break any containing [[Inline Rolls|inline rolls]], like so:
  
Using the indexes appears to break any containing inline rolls, like so:
+
[[File:Reuse-rolls-ex2-bad.png]]
 
+
  
 
Additionally, the indexing is line specific, so this also doesn't work:
 
Additionally, the indexing is line specific, so this also doesn't work:
  
<pre>
+
<pre style="overflow:hidden;white-space:pre-wrap">
 
[[1d20]] + [[1d6]] + [[6]]
 
[[1d20]] + [[1d6]] + [[6]]
 
[[$[[0]] + $[[1]] + $[[2]] ]]
 
[[$[[0]] + $[[1]] + $[[2]] ]]
 
</pre>
 
</pre>
 +
[[File:Reuse-rolls-ex3-bad.png]]
  
These are pretty big limitations if you're just typing rolls into chat, but we can circumvent it through good use of roll templates. For instance, we could hid the actual roll in between roll template fields, and then present them in whatever order we wanted:
+
However, a new line can be achieved by using <code>%NEWLINE%</code>:
  
<pre>
+
<pre style="overflow:hidden;white-space:pre-wrap">
 +
[[1d20]] + [[1d6]] + [[6]] %NEWLINE% [[$[[0]] + $[[1]] + $[[2]] ]]
 +
</pre>
 +
 
 +
These are pretty big limitations if you're just typing rolls into {{Text Chat}}, but we can circumvent it through good use of [[Roll Templates|roll templates]]. For instance, we could hide the actual roll in between roll template fields, and then present them in whatever order we wanted:
 +
 
 +
<pre style="overflow:hidden;white-space:pre-wrap">
 
&{template:default} [[ [[1d20]] + [[1d6]] + [[6]] ]] {{name=My Attack}} {{$[[0]] + $[[1]] + $[[2]]==$[[3]]}}
 
&{template:default} [[ [[1d20]] + [[1d6]] + [[6]] ]] {{name=My Attack}} {{$[[0]] + $[[1]] + $[[2]]==$[[3]]}}
 
</pre>
 
</pre>
Line 45: Line 52:
 
which would give us this output:
 
which would give us this output:
  
[[File:ScottCTrickthumbnail|An example result of the ScottC template]]
+
[[File:Reuse-rolls-ex4-template.png|Reuse Rolls example using roll template]]
  
 
For those with API access, the API sees this message with the proper indexes showing, so any API that handles rolls should react to these indexed rolls just like they were regular rolls.
 
For those with API access, the API sees this message with the proper indexes showing, so any API that handles rolls should react to these indexed rolls just like they were regular rolls.
 +
 +
While you can't nest indexed rolls, you '''can''' nest the roll it's referencing, e.g:
 +
 +
<pre style="overflow:hidden;white-space:pre-wrap">
 +
[[ [[ [[1d20]] + @{str_mod} ]] - @{str_mod} + 6 ]]
 +
</pre>
 +
 +
In this case, <code>index 0</code> will find the result of <code>1d20</code>, <code>index 1</code> will include the <code>str_mod</code>, and <code>index 2</code> will subtract the <code>str_mod</code> from the previous value and add the 6.
  
 
'''What's it allow us to do though?'''
 
'''What's it allow us to do though?'''
  
There's several new things this allows the community to do that were previously locked behind access to the API.
+
There's several new things this allows the community to do that were previously locked behind access to the Mods(API).
  
 
'''Character Sheets'''
 
'''Character Sheets'''
  
When making custom character sheets (or sheets for the repo), one of the big hurdles has been accomodating systems that require you to know multiple things about a complex roll. Something like say the success of a roll in relation to a target number, as well as the value of the roll itself. Or if a given number on a die counts as 0 (or some other number).
+
When making [[BCS|custom character sheets]] (or sheets for the repo), one of the big hurdles has been accommodating systems that require you to know multiple things about a complex roll. Something like say the success of a roll in relation to a target number, as well as the value of the roll itself. Or if a given number on a die counts as 0 (or some other number).
  
 
'''General Macro Creation'''
 
'''General Macro Creation'''
Line 62: Line 77:
  
 
===Reordering Rows===
 
===Reordering Rows===
* https://app.roll20.net/forum/permalink/8761813/ by [[GiGs]]
+
* {{fpl|8761813/ post}} by [[GiGs]]
  
Develops further some ideas based on Scott's original '''Reuse Rolls''' stupid trick.
+
Develops further some ideas based on Scott's original '''Reuse Rolls''' trick.
 +
 
 +
one feature lots of people have asked for over the years, is to be able to roll a set of ability scores, and show the total at the same time. With this new trick, you can do that. For example:
 +
 
 +
<pre style="overflow:hidden;white-space:pre-wrap">
 +
&{template:default} {{name=Stats}} {{total=[[ [[4d6kh3]] + [[4d6kh3]] + [[4d6kh3]] + [[4d6kh3]] + [[4d6kh3]] +[[4d6kh3]] ]] }} {{STR=$[[0]]}} {{DEX=$[[1]]}} {{CON=$[[2]]}} {{INT=$[[3]]}} {{WIS=$[[4]]}} {{CHA=$[[5]]}}
 +
</pre>
 +
This will result in:
 +
 
 +
[[File:Reuse-rolls-rows-ex1.png]]
 +
 
 +
The problem here is it shows the Total first. I haven't found a way to use the <code>$[[ ]]</code> syntax to access a roll that others are nested inside, like Total here? Has anyone else figured out how to do that?
 +
 
 +
 
 +
My trick is: there is way to reorder the rows within the template, if you don't mind using numbers as the row titles:
 +
<pre style="overflow:hidden;white-space:pre-wrap">
 +
&{template:default} {{name=Stats}} {{total=[[ [[4d6kh3]] + [[4d6kh3]] + [[4d6kh3]] + [[4d6kh3]] + [[4d6kh3]] +[[4d6kh3]] ]] }} {{1=$[[0]]}} {{2=$[[1]]}} {{3=$[[2]]}} {{4=$[[3]]}} {{5=$[[4]]}} {{6=$[[5]]}}
 +
</pre>
 +
This will result in:
 +
 
 +
[[File:Reuse-rolls-rows-ex2.png]]
 +
 
 +
It turns out that if your default template row name (the part before the <code>=</code>) is just a number, it gets sorted before any text entries, and in numerical ascending order.
 +
 
 +
If you want text labels, you put them after the <code>=</code>, like so:
 +
<pre style="overflow:hidden;white-space:pre-wrap">
 +
&{template:default} {{name=Stats}} {{total=[[ [[4d6kh3]] + [[4d6kh3]] + [[4d6kh3]] + [[4d6kh3]] + [[4d6kh3]] +[[4d6kh3]] ]] }} {{1=STR: $[[0]]}} {{2=DEX: $[[1]]}} {{3=CON: $[[2]]}} {{4=INT: $[[3]]}} {{5=WIS: $[[4]]}} {{6=CHA: $[[5]]}}
 +
</pre>
 +
 
 +
[[File:Reuse-rolls-rows-ex3.png]]
 +
 
 +
So there you go, another implementation of the new 'feature' (or is it a bug), and another undocumentated feature (or is it a bug?) of [[Roll Templates]].
 +
 
 +
'''Note:''' negative numbers are sorted just like text, they don't change position. '''This trick works only for numbers 0 and higher.''' They don't have to be consecutive. It also doesnt work for [[Inline Rolls|inline rolls]].
 +
 
 +
[[File:Reuse-rolls-rows-ex3.png]]
  
 
===Rolltemplate Helper functions===
 
===Rolltemplate Helper functions===
by '''GiGs'''
+
by '''[[GiGs]]'''
  
* https://app.roll20.net/forum/permalink/9028352/
+
* {{fpl|9028352/ link}}
  
 
'''Note:''' This is specifically for [[BCS|character sheet designers]], but it's an implementation of an earlier trick from this thread that is only documented here.
 
'''Note:''' This is specifically for [[BCS|character sheet designers]], but it's an implementation of an earlier trick from this thread that is only documented here.
  
Here's another nifty and counter-intuitive thing about Resuing rolls:
+
Here's another nifty and counter-intuitive thing about Reusing rolls:
  
 
When using them in a rolltemplate, you can use them with logic functions, like <code>rollGreater()</code>.
 
When using them in a rolltemplate, you can use them with logic functions, like <code>rollGreater()</code>.
  
 
For instance:
 
For instance:
<pre>
+
<pre style="overflow:hidden;white-space:pre-wrap">
 
&{template:custom} [[ [[1d100]] - ?{Target Number?|50}]] {{target=[[?{Target Number?}]]}} {{raw_roll=$[[0]]}} {{difference=$[[1]]}}
 
&{template:custom} [[ [[1d100]] - ?{Target Number?|50}]] {{target=[[?{Target Number?}]]}} {{raw_roll=$[[0]]}} {{difference=$[[1]]}}
 
</pre>
 
</pre>
  
 
and a rolltemplate
 
and a rolltemplate
<pre data-language="html">
+
<pre data-language="html" style="overflow:hidden;white-space:pre-wrap">
 
<rolltemplate class="sheet-rolltemplate-custom">
 
<rolltemplate class="sheet-rolltemplate-custom">
 
       <div class="sheet-content">
 
       <div class="sheet-content">
Line 102: Line 152:
 
===Two Unique Roll Results===
 
===Two Unique Roll Results===
 
by '''Persephone'''
 
by '''Persephone'''
* https://app.roll20.net/forum/permalink/9029428/
+
* {{fpl|9029428/ link}}
  
 
I was trying to find a way to roll 2d8, getting both results separately without getting the same result twice, when I remembered this trick. Turns out it works for inline rolls that are nested inside each other.
 
I was trying to find a way to roll 2d8, getting both results separately without getting the same result twice, when I remembered this trick. Turns out it works for inline rolls that are nested inside each other.
Line 110: Line 160:
 
</pre>
 
</pre>
  
The outer nesting is treated as the last one in the line, so <code><nowiki>$[[0]]</nowiki></code> gives you the result of the first inline roll in the deepest layer of the roll while <code><nowiki>$[[1]]</nowiki></code> gives you the same result as the complete roll. If the nested 1d8 results in a 4, the outer roll becomes 1d8r4 so it rerolls any results of 4. The <code><nowiki>$[[0]]</nowiki></code> will show an output of 4 and the inline roll will have a result of any number between 1 and 8, except for 4.
+
The outer nesting is treated as the last one in the line, so <code><nowiki>$[[0]]</nowiki></code> gives you the result of the first inline roll in the deepest layer of the roll while <code><nowiki>$[[1]]</nowiki></code> gives you the same result as the complete roll. If the nested <code>1d8</code> results in a <code>4</code>, the outer roll becomes <code>1d8r4</code> so it rerolls any results of <code>4</code>. The <code><nowiki>$[[0]]</nowiki></code> will show an output of <code>4</code> and the inline roll will have a result of any number between <code>1</code> and <code>8</code>, except for <code>4</code>.
  
 
I haven't yet tested multiple nested layers or multiple inline rolls within the main roll, but I suspect preventing more than 2 rolls from matching would get quite complex, if at all possible.
 
I haven't yet tested multiple nested layers or multiple inline rolls within the main roll, but I suspect preventing more than 2 rolls from matching would get quite complex, if at all possible.
  
('''Comment''': GiGs would rather call this something like ''Multiple Rolls - Each Unique'')
+
('''Comment''': [[GiGs]] would rather call this something like ''Multiple Rolls - Each Unique'')
  
 
===Reusing Rolls (advanced)===
 
===Reusing Rolls (advanced)===
by '''Gibli'''
+
{{fpl|9091003/ example}} by '''Gibli'''
* https://app.roll20.net/forum/permalink/9091003/
+
  
I always wanted to be able to re-use a Roll in a subsidiary Roll, but as stated by [https://app.roll20.net/forum/permalink/8747581/ Scott C. here], it breaks the inline Roll.
 
  
 +
I always wanted to be able to re-use a Roll in a subsidiary Roll, but as stated by Scott C. {{fpl|8747581/ here}}, it breaks the [[Inline Roll]].
  
So, here I thought of a workaround : why not call an Ability depending of the result of my Roll through a button ?
+
 
 +
So, here I thought of a workaround : why not call an Ability depending of the result of my Roll through a button, like making a [[Chat Menu]] ?
 
It might ask a lot of work most of the time, but in some cases it's pretty simple and quick to put in place.
 
It might ask a lot of work most of the time, but in some cases it's pretty simple and quick to put in place.
  
 +
{| role="presentation" class="wikitable mw-collapsible mw-collapsed"
 +
| '''What didn't work'''
 +
|-
 +
| Initial attempt:
  
However, it didn't work through my first attempt.
+
I have a trap which when you fall in it make you hit by 1d4 spikes, each spike doing 1d4+2 damages.
  
 
+
Then, I wanna have something like this(Of course, it doesn't work as is.):
Here is an example : I have a trap which when you fall in it make you hit by 1d4 spikes, each spike doing 1d4+2 damages.
+
<pre style="overflow:hidden;white-space:pre-wrap">
 
+
Then, I wanna have something like this :
+
<pre>
+
 
[[1d4]] [[ $[[0]]d4 + 2*$[[0]] ]]
 
[[1d4]] [[ $[[0]]d4 + 2*$[[0]] ]]
 
</pre>
 
</pre>
Of course, it doesn't work as is.
 
  
So, I put them in different abilities with a call through a button like this :
+
 
 +
* Naming the abilities <code>PikesDamages1</code> to <code>PikesDamages4</code> didn't work, as pressing the  roll button on <code>Trap</code> will not process <code><nowiki>PikesDamages$[[0]]</nowiki></code>, but instead interpret the ability name as <code>PikesDamages Rolling 1d4 = (1)'>1</code>
 +
 
 +
* When you put the caller to the previous roll <code><nowiki>$[[0]]</nowiki></code> in the parenthesis for the name of the ability, it is replaced by a text such like this :
 +
 
 +
 
 +
<code><nowiki>[Throw](~PikesDamages Rolling 1d4 = (1)'>1)</nowiki></code>
 +
 
 +
This text is specifically for a call to a Roll of 1d4 which resulted in a 1.
 +
 
 +
For you to have spaces in the name of an Ability, you can simply write the name you want anywhere and then simply copy/past it.
 +
Spaces are replaced by dashes only while you type them, the copy/past bypass this.
 +
|}
 +
 
 +
 
 +
After some testing, saving <code>Trap</code> as a character [[Journal#Abilities|abilities]] with a roll button for the damage:
 
'''Trap :'''
 
'''Trap :'''
<pre>
+
<pre style="overflow:hidden;white-space:pre-wrap">
 
&{template:default} {{name=Trap}} {{Pikes=[[1d4]]}} {{Damages=[Throw](~PikesDamages$[[0]])}}
 
&{template:default} {{name=Trap}} {{Pikes=[[1d4]]}} {{Damages=[Throw](~PikesDamages$[[0]])}}
 
</pre>
 
</pre>
'''PikesDamages1 :'''
+
Then save these 4 with '''exactly''' these names, as more character abilities:
<pre>
+
 
 +
<pre style="overflow:hidden;white-space:pre-wrap">
 +
PikesDamages Rolling 1d4 = (1)'>1
 
&{template:default} {{name=Pikes Damages}} {{Damages=[[1d4+2]]}}
 
&{template:default} {{name=Pikes Damages}} {{Damages=[[1d4+2]]}}
</pre>
+
 
'''PikesDamages2 :'''
+
PikesDamages Rolling 1d4 = (2)'>2
<pre>
+
 
&{template:default} {{name=Pikes Damages}} {{Damages=[[2d4+4]]}}
 
&{template:default} {{name=Pikes Damages}} {{Damages=[[2d4+4]]}}
</pre>
+
 
'''PikesDamages3 :'''
+
PikesDamages Rolling 1d4 = (3)'>3
<pre>
+
 
&{template:default} {{name=Pikes Damages}} {{Damages=[[3d4+6]]}}
 
&{template:default} {{name=Pikes Damages}} {{Damages=[[3d4+6]]}}
</pre>
+
 
'''PikesDamages4 :'''
+
PikesDamages Rolling 1d4 = (4)'>4
<pre>
+
 
&{template:default} {{name=Pikes Damages}} {{Damages=[[4d4+8]]}}
 
&{template:default} {{name=Pikes Damages}} {{Damages=[[4d4+8]]}}
 
</pre>
 
</pre>
  
The trick is that the previous Roll shall be replace by 1, 2, 3 or 4 in the name of my Ability, making the button call the correct one.
+
[[File:Reuse-rolls-advanced-ability-button-ex.gif|700px|thumbnail|center|Rolling the Trap. Depending on the initial <code>1d4</code> result, it changes which dmg ability is used for rolling damage.]]
  
 +
'''Note(Gibli):''' I haven't found why, but it seems that the button need to be put at the end of the rolltemplate, it might not appear in the chat otherwise. And be careful if your rolltemplate has many intricate [[Inline Rolls]], try to always put the one you want to Reuse first, and your button last in the rolltemplate.
  
Yet, as I said, my first try didn't work for a pretty simple reason :
+
===Computed rolls and order independence===
 +
[https://app.roll20.net/forum/permalink/10534037/ Rainbowencoder]
  
When you pu the caller to the previous roll <code><nowiki>$[[0]]</nowiki></code> in the parenthesis for the name of the ability, it is replaced by a text such like this :
+
With the addition of [[CRP|computed rolls]] comes new syntax to reference those rolls.
 +
 
 +
So if you have a roll <code><nowiki>$[[0]]</nowiki></code> you can access the computed roll based on it via <code><nowiki>$[[0.computed]]</nowiki></code> additionally all rolls have a computed roll that defaults to the original roll. You can even use the <code>.computed</code> version without requiring a [[Roll Template]] at all.
 +
 
 +
Referencing a roll in this way also doesn't interfere with nested rolls like a standard reference would.
 +
 
 +
So while this breaks:
 +
<pre>
 +
$[[0]] plus $[[1]] equals [[ [[1d10]] + [[2d6]] ]]</pre>
 +
 
 +
Using the <code>.computed</code> version allows it to work
 +
<pre>
 +
$[[0.computed]] plus $[[1.computed]] equals [[ [[1d10]] + [[2d6]] ]]</pre>
 +
 
 +
 
 +
This could also be used when [https://app.roll20.net/forum/permalink/9112320/ Overwriting template fields in macros]. Since the fields you overwrite have to be before the ones that do the conditional overwriting you wouldn't have previously been able to reference any of the rolls used in determining the decision but with this you can
 +
 
 +
=== Reusing rolls, [] pair matter and math ===
 +
* https://app.roll20.net/forum/post/10690257/reusing-rolls-pair-matter-and-math-seems-to-possible
 +
 
 +
Long thread with many tricks and insights
 +
 
 +
=== Macro curiosities, or how to overcomplicate everything ===
 +
In the [https://app.roll20.net/forum/post/10693202/macro-curiosities-or-how-to-overcomplicate-everything forum thread Macro curiosities, or how to overcomplicate everything by RainbowEncoder], RainbowEncoder shows a way to duplicate the result of a roll and to reuse it multiple times for further rolls or calculation shown in [https://app.roll20.net/forum/post/10693202/macro-curiosities-or-how-to-overcomplicate-everything/?pageforid=10693212#post-10693212 the post about Improved roll index manipulation and Duplicating a roll result for further calculations].
 +
 
 +
===Reusing Rolls to get additional crit damage===
 +
* [https://app.roll20.net/forum/permalink/10925029/ trick] by Spencer
  
 
<pre>
 
<pre>
[Throw](~PikesDamages Rolling 1d4 = (1)'>1)
+
&{template:default} {{name=Crit}} {{2= Damage : [[ [[1d6+5]]+[[floor(( $[[1]]/50)d6)]] ]]}} {{1=Check : [[ [[1d20+5]] ]]}}
 
</pre>
 
</pre>
  
This text is specifically for a call to a Roll of 1d4 which resulted in a 1.
+
===Toggleable template fields, an update on reusing rolls===
 +
{{fpl|11832831 post}} by RainbowEncoder (March 2024)
  
 +
Following on from the [https://app.roll20.net/forum/permalink/11765994/ earlier toggleable template fields post]: Attempting to reuse rolls in a hide-able section would prevent that section from being hidden. However this problem can be avoided by using [[HTML Entities]] to partially escape any roll reference. So <code><nowiki>$[[0]]</nowiki></code> becomes <code><nowiki>$[&lsqb;0&rsqb;]</nowiki></code>. Reusing a roll this way doesn't interact with the rest of the roll parsing making it safe to use for our purposes here. (Note: It only works when using roll templates)
  
So here is the workaround :
+
'''Toggleable template fields, roll controlled'''
  
Rather than calling the abilities <code>PikesDamages1</code> to <code>PikesDamages4</code>, I called them <code>PikesDamages Rolling 1d4 = (1)'>1</code> to <code>PikesDamages  Rolling 1d4 = (4)'>4</code>, and it works perfectly !
+
Those familiar with reusing rolls know that trying to reuse a roll before it happens breaks any roll it was nested inside of. This behaviour can be used to control if a set of template fields is inside a working roll or not, since a "broken" roll won't hide the fields but a working roll will. By using a [https://app.roll20.net/forum/permalink/10693210/ dynamic roll reference] to conditionally reference a nested roll within a hide-able section. That hide-able section can then be hidden or shown based on a roll result.
  
 +
'''A single section example:'''
  
For you to have spaces in the name of an Ability, you can simply write the name you want anywhere and then simply copy/past it.
+
In this example {{c|2d4}} is rolled and on double one will show "Snake Eyes!" after the roll plus a "Bonus Section"
Spaces are replaced by dashes only while you type them, the copy/past bypass this.
+
<pre>
 +
$[[$[[1]]]] [[[ [[ {0,[[2d4]]}=2*2 ]] ]]] &{template:default} {{2d4=$[[0]]}} [[[0 [[0]] {{2d4=$[&lsqb;0&rsqb;] Snake Eyes!}} {{Bonus Section}}]]]
 +
</pre>
  
 +
'''A multi section example'''
  
'''Note(Gibli):''' I haven't found why, but it seems that the button need to be put at the end of the RollTemplate. He might not appear in the chat otherwise. And be careful if your RollTemplate has many intricate Inline Rolls, try to always put the one you want to Reuse first, and your button last in the RollTemplate.
+
In this example a {{c|d6}} is rolled that highlights a roll of 1 and a roll of 6 with bonus d6
 +
<pre>
 +
$[[$[[1]]]] [[[ [[ {1,6,6}=[[d6]]*2 ]] ]]] &{template:default} {{d6=$[[0]]}} [[[0 [[0]] {{d6=$[&lsqb;0&rsqb;] One!}} ]]] [[[0 [[0]] {{d6=$[&lsqb;0&rsqb;] Six!}} {{Bonus d6=$[&lsqb;5&rsqb;]}} ]]] [[d6 Bonus]]
 +
</pre>
  
 +
==Sheets using this trick==
 +
* {{repo|Roll20/roll20-character-sheets/tree/master/Barbaric Barbaric!}} "reuse roll" trick is used for determining if a <code>2d6</code> roll is either a <code>2</code> or <code>12</code>, which in the system are crit success and fumble. • by [[Andreas J.]]
  
 
==See Also==
 
==See Also==
 +
* [[Toggleable template fields]]
 +
* [[Inline Rolls]]
 
* '''[[Complete Guide to Macros & Rolls‎]]'''
 
* '''[[Complete Guide to Macros & Rolls‎]]'''
 
** {{Text Chat}} - where the roll results appear, & info on the common chat commands
 
** {{Text Chat}} - where the roll results appear, & info on the common chat commands
 
** [[Dice Reference]] - Comprehensive list of how the Roll20 dice-rolling syntax works, and list the features available
 
** [[Dice Reference]] - Comprehensive list of how the Roll20 dice-rolling syntax works, and list the features available
** [[Macros]] - How to create macros, and other info on how the Roll20 <span style="font-family:Pictos;">q</span>Text Chat works, like referencing stats on character sheets, roll queries, nesting macros & initiative
+
** [[Macros]] - How to create macros, and other info on how the Roll20 {{Text Chat}} works, like referencing stats on character sheets, roll queries, nesting macros & initiative
*** [[Reusing Rolls]]
+
*** [[Chat Menus]]
 
** [[Roll Templates]] - a method of formatting roll results in the chat, with some extra functions
 
** [[Roll Templates]] - a method of formatting roll results in the chat, with some extra functions
 
** [[API]]''(Pro Only)'' - API commands can be used in the <span style="font-family:Pictos;">q</span>Text Chat
 
** [[API]]''(Pro Only)'' - API commands can be used in the <span style="font-family:Pictos;">q</span>Text Chat
* [[BCS|Building Character Sheets]]
+
* [[Building Character Sheets]]
<br>
+
 
<br>
+
 
[[Category:Tips]]
 
[[Category:Tips]]
 
[[Category:Macros]]
 
[[Category:Macros]]
 +
[[Category:Roll Templates]]

Latest revision as of 13:13, 10 May 2024

In early 2020, it was noticed that you could re-use roll in macros without using API. This page lists some of the top posts and comments that figures out uses for it.


Contents

[edit] Collected Tricks

[edit] Scott C's Original Trick

Stupid Roll20 Tricks (and some clever ones)(Forum) - Initial Trick writeup - Scott C

Disclaimer: This trick takes advantage of emergent behavior that may not be intended and may be patched

I can't take credit for this trick. Syneran discovered the capability. But, long story short, it is actually possible to reuse rolls with some small caveats. Here's a summary of the info discovered in the linked forum thread:

The chat accepts the inline roll indexing used in the API (and apparently the roll parser itself), so you can do:

[[ [[1d20]] + [[1d6]] + [[6]] ]] = $[[0]] + $[[1]] + $[[2]]

And get an output that would read like this:

Reuse-rolls-ex1.png

The limited part is you can't use those indexed rolls inside other rolls. So for instance, you cannot reverse the above output in the following way:

[[1d20]] + [[1d6]] + [[6]] = [[$[[0]] + $[[1]] + $[[2]] ]]

Using the indexes appears to break any containing inline rolls, like so:

Reuse-rolls-ex2-bad.png

Additionally, the indexing is line specific, so this also doesn't work:

[[1d20]] + [[1d6]] + [[6]]
[[$[[0]] + $[[1]] + $[[2]] ]]

Reuse-rolls-ex3-bad.png

However, a new line can be achieved by using %NEWLINE%:

[[1d20]] + [[1d6]] + [[6]] %NEWLINE% [[$[[0]] + $[[1]] + $[[2]] ]]

These are pretty big limitations if you're just typing rolls into q Text Chat, but we can circumvent it through good use of roll templates. For instance, we could hide the actual roll in between roll template fields, and then present them in whatever order we wanted:

&{template:default} [[ [[1d20]] + [[1d6]] + [[6]] ]] {{name=My Attack}} {{$[[0]] + $[[1]] + $[[2]]==$[[3]]}}

which would give us this output:

Reuse Rolls example using roll template

For those with API access, the API sees this message with the proper indexes showing, so any API that handles rolls should react to these indexed rolls just like they were regular rolls.

While you can't nest indexed rolls, you can nest the roll it's referencing, e.g:

[[ [[ [[1d20]] + @{str_mod} ]] - @{str_mod} + 6 ]]

In this case, index 0 will find the result of 1d20, index 1 will include the str_mod, and index 2 will subtract the str_mod from the previous value and add the 6.

What's it allow us to do though?

There's several new things this allows the community to do that were previously locked behind access to the Mods(API).

Character Sheets

When making custom character sheets (or sheets for the repo), one of the big hurdles has been accommodating systems that require you to know multiple things about a complex roll. Something like say the success of a roll in relation to a target number, as well as the value of the roll itself. Or if a given number on a die counts as 0 (or some other number).

General Macro Creation

Now we can create macros that do our math for us. Total the damage from a complicated attack (or one that hit several times), display the parts of a roll so that what went into that roll is visible without needing to hover over it. And I'm sure folks will come up with quite a few other ideas that I haven't even thought of.

[edit] Reordering Rows

Develops further some ideas based on Scott's original Reuse Rolls trick.

one feature lots of people have asked for over the years, is to be able to roll a set of ability scores, and show the total at the same time. With this new trick, you can do that. For example:

&{template:default} {{name=Stats}} {{total=[[ [[4d6kh3]] + [[4d6kh3]] + [[4d6kh3]] + [[4d6kh3]] + [[4d6kh3]] +[[4d6kh3]] ]] }} {{STR=$[[0]]}} {{DEX=$[[1]]}} {{CON=$[[2]]}} {{INT=$[[3]]}} {{WIS=$[[4]]}} {{CHA=$[[5]]}}

This will result in:

Reuse-rolls-rows-ex1.png

The problem here is it shows the Total first. I haven't found a way to use the $[[ ]] syntax to access a roll that others are nested inside, like Total here? Has anyone else figured out how to do that?


My trick is: there is way to reorder the rows within the template, if you don't mind using numbers as the row titles:

&{template:default} {{name=Stats}} {{total=[[ [[4d6kh3]] + [[4d6kh3]] + [[4d6kh3]] + [[4d6kh3]] + [[4d6kh3]] +[[4d6kh3]] ]] }} {{1=$[[0]]}} {{2=$[[1]]}} {{3=$[[2]]}} {{4=$[[3]]}} {{5=$[[4]]}} {{6=$[[5]]}}

This will result in:

Reuse-rolls-rows-ex2.png

It turns out that if your default template row name (the part before the =) is just a number, it gets sorted before any text entries, and in numerical ascending order.

If you want text labels, you put them after the =, like so:

&{template:default} {{name=Stats}} {{total=[[ [[4d6kh3]] + [[4d6kh3]] + [[4d6kh3]] + [[4d6kh3]] + [[4d6kh3]] +[[4d6kh3]] ]] }} {{1=STR: $[[0]]}} {{2=DEX: $[[1]]}} {{3=CON: $[[2]]}} {{4=INT: $[[3]]}} {{5=WIS: $[[4]]}} {{6=CHA: $[[5]]}}

Reuse-rolls-rows-ex3.png

So there you go, another implementation of the new 'feature' (or is it a bug), and another undocumentated feature (or is it a bug?) of Roll Templates.

Note: negative numbers are sorted just like text, they don't change position. This trick works only for numbers 0 and higher. They don't have to be consecutive. It also doesnt work for inline rolls.

Reuse-rolls-rows-ex3.png

[edit] Rolltemplate Helper functions

by GiGs

Note: This is specifically for character sheet designers, but it's an implementation of an earlier trick from this thread that is only documented here.

Here's another nifty and counter-intuitive thing about Reusing rolls:

When using them in a rolltemplate, you can use them with logic functions, like rollGreater().

For instance:

&{template:custom} [[ [[1d100]] - ?{Target Number?|50}]] {{target=[[?{Target Number?}]]}} {{raw_roll=$[[0]]}} {{difference=$[[1]]}}

and a rolltemplate

<rolltemplate class="sheet-rolltemplate-custom">
      <div class="sheet-content">
        <div class="sheet-key">Target</div>
        <div class="sheet-value">{{target}}</div>
        <div class="sheet-key">Raw Roll</div>
        <div class="sheet-value">{{raw_roll}} {{#rollGreater() raw_roll target}} (above Target) {{/rollGreater() raw_roll target}}</div>
        <div class="sheet-key">Difference</div>
        <div class="sheet-value">{{difference}}</div>
    </div>
</rolltemplate>

This will show the text (above Target) for raw_rolls that roll above the target - even though row_roll is one of these weird pseudo-inline rolls.

This makes these quantities even more useful for character sheet design.

[edit] Two Unique Roll Results

by Persephone

I was trying to find a way to roll 2d8, getting both results separately without getting the same result twice, when I remembered this trick. Turns out it works for inline rolls that are nested inside each other.

[[1d8r[[1d8]]]], $[[0]]

The outer nesting is treated as the last one in the line, so $[[0]] gives you the result of the first inline roll in the deepest layer of the roll while $[[1]] gives you the same result as the complete roll. If the nested 1d8 results in a 4, the outer roll becomes 1d8r4 so it rerolls any results of 4. The $[[0]] will show an output of 4 and the inline roll will have a result of any number between 1 and 8, except for 4.

I haven't yet tested multiple nested layers or multiple inline rolls within the main roll, but I suspect preventing more than 2 rolls from matching would get quite complex, if at all possible.

(Comment: GiGs would rather call this something like Multiple Rolls - Each Unique)

[edit] Reusing Rolls (advanced)

example(Forum) by Gibli


I always wanted to be able to re-use a Roll in a subsidiary Roll, but as stated by Scott C. here(Forum), it breaks the Inline Roll.


So, here I thought of a workaround : why not call an Ability depending of the result of my Roll through a button, like making a Chat Menu ? It might ask a lot of work most of the time, but in some cases it's pretty simple and quick to put in place.

What didn't work
Initial attempt:

I have a trap which when you fall in it make you hit by 1d4 spikes, each spike doing 1d4+2 damages.

Then, I wanna have something like this(Of course, it doesn't work as is.):

[[1d4]] [[ $[[0]]d4 + 2*$[[0]] ]]


  • Naming the abilities PikesDamages1 to PikesDamages4 didn't work, as pressing the roll button on Trap will not process PikesDamages$[[0]], but instead interpret the ability name as PikesDamages Rolling 1d4 = (1)'>1
  • When you put the caller to the previous roll $[[0]] in the parenthesis for the name of the ability, it is replaced by a text such like this :


[Throw](~PikesDamages Rolling 1d4 = (1)'>1)

This text is specifically for a call to a Roll of 1d4 which resulted in a 1.

For you to have spaces in the name of an Ability, you can simply write the name you want anywhere and then simply copy/past it. Spaces are replaced by dashes only while you type them, the copy/past bypass this.


After some testing, saving Trap as a character abilities with a roll button for the damage: Trap :

&{template:default} {{name=Trap}} {{Pikes=[[1d4]]}} {{Damages=[Throw](~PikesDamages$[[0]])}}

Then save these 4 with exactly these names, as more character abilities:

PikesDamages Rolling 1d4 = (1)'>1
&{template:default} {{name=Pikes Damages}} {{Damages=[[1d4+2]]}}

PikesDamages Rolling 1d4 = (2)'>2
&{template:default} {{name=Pikes Damages}} {{Damages=[[2d4+4]]}}

PikesDamages Rolling 1d4 = (3)'>3
&{template:default} {{name=Pikes Damages}} {{Damages=[[3d4+6]]}}

PikesDamages Rolling 1d4 = (4)'>4
&{template:default} {{name=Pikes Damages}} {{Damages=[[4d4+8]]}}
Rolling the Trap. Depending on the initial 1d4 result, it changes which dmg ability is used for rolling damage.

Note(Gibli): I haven't found why, but it seems that the button need to be put at the end of the rolltemplate, it might not appear in the chat otherwise. And be careful if your rolltemplate has many intricate Inline Rolls, try to always put the one you want to Reuse first, and your button last in the rolltemplate.

[edit] Computed rolls and order independence

Rainbowencoder

With the addition of computed rolls comes new syntax to reference those rolls.

So if you have a roll $[[0]] you can access the computed roll based on it via $[[0.computed]] additionally all rolls have a computed roll that defaults to the original roll. You can even use the .computed version without requiring a Roll Template at all.

Referencing a roll in this way also doesn't interfere with nested rolls like a standard reference would.

So while this breaks:

$[[0]] plus $[[1]] equals [[ [[1d10]] + [[2d6]] ]]

Using the .computed version allows it to work

$[[0.computed]] plus $[[1.computed]] equals [[ [[1d10]] + [[2d6]] ]]


This could also be used when Overwriting template fields in macros. Since the fields you overwrite have to be before the ones that do the conditional overwriting you wouldn't have previously been able to reference any of the rolls used in determining the decision but with this you can

[edit] Reusing rolls, [] pair matter and math

Long thread with many tricks and insights

[edit] Macro curiosities, or how to overcomplicate everything

In the forum thread Macro curiosities, or how to overcomplicate everything by RainbowEncoder, RainbowEncoder shows a way to duplicate the result of a roll and to reuse it multiple times for further rolls or calculation shown in the post about Improved roll index manipulation and Duplicating a roll result for further calculations.

[edit] Reusing Rolls to get additional crit damage

&{template:default} {{name=Crit}} {{2= Damage : [[ [[1d6+5]]+[[floor(( $[[1]]/50)d6)]] ]]}} {{1=Check : [[ [[1d20+5]] ]]}}

[edit] Toggleable template fields, an update on reusing rolls

post(Forum) by RainbowEncoder (March 2024)

Following on from the earlier toggleable template fields post: Attempting to reuse rolls in a hide-able section would prevent that section from being hidden. However this problem can be avoided by using HTML Entities to partially escape any roll reference. So $[[0]] becomes $[&lsqb;0&rsqb;]. Reusing a roll this way doesn't interact with the rest of the roll parsing making it safe to use for our purposes here. (Note: It only works when using roll templates)

Toggleable template fields, roll controlled

Those familiar with reusing rolls know that trying to reuse a roll before it happens breaks any roll it was nested inside of. This behaviour can be used to control if a set of template fields is inside a working roll or not, since a "broken" roll won't hide the fields but a working roll will. By using a dynamic roll reference to conditionally reference a nested roll within a hide-able section. That hide-able section can then be hidden or shown based on a roll result.

A single section example:

In this example 2d4 is rolled and on double one will show "Snake Eyes!" after the roll plus a "Bonus Section"

$[[$[[1]]]] [[[ [[ {0,[[2d4]]}=2*2 ]] ]]] &{template:default} {{2d4=$[[0]]}} [[[0 [[0]] {{2d4=$[&lsqb;0&rsqb;] Snake Eyes!}} {{Bonus Section}}]]]

A multi section example

In this example a d6 is rolled that highlights a roll of 1 and a roll of 6 with bonus d6

$[[$[[1]]]] [[[ [[ {1,6,6}=[[d6]]*2 ]] ]]] &{template:default} {{d6=$[[0]]}} [[[0 [[0]] {{d6=$[&lsqb;0&rsqb;] One!}} ]]] [[[0 [[0]] {{d6=$[&lsqb;0&rsqb;] Six!}} {{Bonus d6=$[&lsqb;5&rsqb;]}} ]]] [[d6 Bonus]]

[edit] Sheets using this trick

  • Barbaric! "reuse roll" trick is used for determining if a 2d6 roll is either a 2 or 12, which in the system are crit success and fumble. • by Andreas J.

[edit] See Also