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 "Toggleable template fields"

From Roll20 Wiki

Jump to: navigation, search
m (formatting)
Line 1: Line 1:
 
{{revdate}}{{NavMacroDocs}}
 
{{revdate}}{{NavMacroDocs}}
If [[Roll Template]] fields are inside of an [[Inline Roll|inline roll]] they will be turned into a roll comment at which point they won't appear as part of the final template. So by controlling whether they are inside a roll or not you can show or hide multiple template fields at once. However the final roll must still be a valid roll, so starting a roll with <code><nowiki>[[0</nowiki></code>(without the closing <code><nowiki>]]</nowiki></code>) ensures that.
+
If [[Roll Template]] fields are inside of an [[Inline Roll|inline roll]] they will be turned into a roll comment at which point they won't appear as part of the final template. So by controlling whether they are inside a roll or not you can show or hide multiple template fields at once. However the final roll must still be a valid roll, so starting a roll with <code><nowiki>[[[0</nowiki></code> ensures that (with the closing <code><nowiki>]]]</nowiki></code> after the fields you want to be toggled). Additional care is also required when [[Reusing Rolls]] since the syntax will prevent a section from being hidden. In order to reuse rolls the roll reference needs to partially escaped using [[HTML Entities]]; Eg. {{c|<nowiki>$[[0]]</nowiki>}} becomes {{c|$[&lsqb;0&rsqb;]}}
 
==Query controlled toggles==
 
==Query controlled toggles==
 
===Simple single section===
 
===Simple single section===
 
The simplest way to achieve this is by using a query that will open an inline roll when the fields are to be hidden.
 
The simplest way to achieve this is by using a query that will open an inline roll when the fields are to be hidden.
The query would be of the form <code>?{Section|Show,|Hide,[[0}</code> and the end of the macro must include <code>]]</code> to actually hide those fields in between.
+
The query would be of the form <code><nowiki>?{Section|Show,|Hide,[[[0}</nowiki></code> and the end of the macro must include <code>]]]</code> to actually hide those fields in between.
 
A full example being
 
A full example being
<pre>&{template:default} {{Always Show=[[d20]]}} ?{Section|Show,|Hide,[[0} {{Sometimes Show=[[1d8]]}} {{More Optional Fields}} ]]</pre>
+
<pre>&{template:default} {{Always Show=[[d20]]}} ?{Section|Show,|Hide,[[[0} {{Sometimes Show=[[1d8]]}} {{More Optional Fields}} ]]]</pre>
There are a couple of caveats. Firstly any rolls made after the toggle-able section can behave oddly, so it only works once and should be at the end of your macro. Secondly you cannot [[Reusing Rolls|reuse rolls]] since trying to reuse a roll inside another tends to break the roll which prevents it from hiding the template fields.
+
There are a couple of caveats. Firstly any rolls made after the toggle-able section can behave oddly, so it only works once and should be at the end of your macro.
 
===Multiple sections===
 
===Multiple sections===
 
A more advanced variant that can be used multiple times exists that makes extensive use of [[Reusing Rolls]].
 
A more advanced variant that can be used multiple times exists that makes extensive use of [[Reusing Rolls]].
 
In this variant rolls are specified up front and then referenced within the template fields. The control comes from a query being used to determine if a reference is an actual reference or a roll. A reference will force the template field to display whereas a roll gets hidden.<br/>
 
In this variant rolls are specified up front and then referenced within the template fields. The control comes from a query being used to determine if a reference is an actual reference or a roll. A reference will force the template field to display whereas a roll gets hidden.<br/>
The query takes the form <code>?{Section|Show,$|Hide,+}</code> the opening <code>[[0</code> and closing <code>]]</code> of the inline roll go around the template fields you want to toggle.
+
The query takes the form <code>?{Section|Show,$|Hide,+}</code> the opening <code>[[[0</code> and closing <code>]]]</code> of the inline roll go around the template fields you want to toggle.
 
A toggleable roll reference would then look like <code><nowiki>?{Section|Show,$|Hide,+}[[1]]</nowiki></code>.
 
A toggleable roll reference would then look like <code><nowiki>?{Section|Show,$|Hide,+}[[1]]</nowiki></code>.
 
A full example being
 
A full example being
Line 21: Line 21:
 
You can also split sections to give finer control over the ordering of the template fields. For example:
 
You can also split sections to give finer control over the ordering of the template fields. For example:
 
<pre>[[d20 Always Shown]] [[d4 Sometimes Shown]] &{template:default} [[0 ?{Optional Section|Show,$|Hide,+}[[-1]] {{Using Optional Section}} ]] {{Always Show=$[[0]]}} [[0 {{Sometimes Show=?{Optional Section}[[1]]}} ]]</pre>
 
<pre>[[d20 Always Shown]] [[d4 Sometimes Shown]] &{template:default} [[0 ?{Optional Section|Show,$|Hide,+}[[-1]] {{Using Optional Section}} ]] {{Always Show=$[[0]]}} [[0 {{Sometimes Show=?{Optional Section}[[1]]}} ]]</pre>
 +
==Roll controlled toggles==
 +
When trying to reuse a roll earlier than it actually appears will break 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 {{forum|permalink/10693210/ dynamic roll reference}} to conditionally reference a nested roll within a toggleable section. That section can then be hidden or shown based on a roll result. To display rolls within these sections requires escaped reusing rolls as described at the top.
 +
===Single section===
 +
In this example 2d4 is rolled and on double one will show "Snake Eyes!" after the roll plus a "Bonus Section". When the roll is double one it creates a roll reference of {{c|<nowiki>$[[2]]</nowiki>}} that points to the nested roll inside the toggleable section causing it to display
 +
<pre><nowiki>$[[$[[1]]]] [[[ [[ {0,[[2d4]]}=2*2 ]] ]]] &{template:default} {{2d4=$[[0]]}} [[[0 [[0]] {{2d4=$[&lsqb;0&rsqb;] Snake Eyes!}} {{Bonus Section}}]]]</nowiki></pre>
 +
===Multiple sections===
 +
In this example a d6 is rolled that highlights a roll of 1 and a roll of 6 with bonus d6. On a roll of 1 or 6 this creates a roll reference of 2, or 4 pointing at their respective nested rolls causing their containing toggleable section to be shown if their roll reference is created or remain hidden otherwise.
 +
<pre><nowiki>$[[$[[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]]</nowiki></pre>
  
 
==Related Pages==
 
==Related Pages==

Revision as of 21:17, 12 June 2024

If Roll Template fields are inside of an inline roll they will be turned into a roll comment at which point they won't appear as part of the final template. So by controlling whether they are inside a roll or not you can show or hide multiple template fields at once. However the final roll must still be a valid roll, so starting a roll with [[[0 ensures that (with the closing ]]] after the fields you want to be toggled). Additional care is also required when Reusing Rolls since the syntax will prevent a section from being hidden. In order to reuse rolls the roll reference needs to partially escaped using HTML Entities; Eg. $[[0]] becomes $[&lsqb;0&rsqb;]

Contents

Query controlled toggles

Simple single section

The simplest way to achieve this is by using a query that will open an inline roll when the fields are to be hidden. The query would be of the form ?{Section|Show,|Hide,[[[0} and the end of the macro must include ]]] to actually hide those fields in between. A full example being

&{template:default} {{Always Show=[[d20]]}} ?{Section|Show,|Hide,[[[0} {{Sometimes Show=[[1d8]]}} {{More Optional Fields}} ]]]

There are a couple of caveats. Firstly any rolls made after the toggle-able section can behave oddly, so it only works once and should be at the end of your macro.

Multiple sections

A more advanced variant that can be used multiple times exists that makes extensive use of Reusing Rolls. In this variant rolls are specified up front and then referenced within the template fields. The control comes from a query being used to determine if a reference is an actual reference or a roll. A reference will force the template field to display whereas a roll gets hidden.
The query takes the form ?{Section|Show,$|Hide,+} the opening [[[0 and closing ]]] of the inline roll go around the template fields you want to toggle. A toggleable roll reference would then look like ?{Section|Show,$|Hide,+}[[1]]. A full example being

[[1d20 Always Shown]] [[1d8 Section 1]] [[1d6 Section 2]] &{template:default} {{Always Show=$[[0]]}} [[0 {{Using Section 1}} {{Section 1=?{Section 1|Show,$|Hide,+}[[1]]}} ]] [[0 {{Using Section 2}} {{Section 2=?{Section 2|Show,$|Hide,+}[[2]]}} ]]

If you want to have a toggleable section that doesn't include any rolls you can use a reference of -1 outside of the template fields but still inside the encompassing roll. Such as

[[0 ?{Text only section|Show,$|Hide,+}[[-1]] {{Text Only Section}} ]]

You can also split sections to give finer control over the ordering of the template fields. For example:

[[d20 Always Shown]] [[d4 Sometimes Shown]] &{template:default} [[0 ?{Optional Section|Show,$|Hide,+}[[-1]] {{Using Optional Section}} ]] {{Always Show=$[[0]]}} [[0 {{Sometimes Show=?{Optional Section}[[1]]}} ]]

Roll controlled toggles

When trying to reuse a roll earlier than it actually appears will break 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(Forum) to conditionally reference a nested roll within a toggleable section. That section can then be hidden or shown based on a roll result. To display rolls within these sections requires escaped reusing rolls as described at the top.

Single section

In this example 2d4 is rolled and on double one will show "Snake Eyes!" after the roll plus a "Bonus Section". When the roll is double one it creates a roll reference of $[[2]] that points to the nested roll inside the toggleable section causing it to display

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

Multiple sections

In this example a d6 is rolled that highlights a roll of 1 and a roll of 6 with bonus d6. On a roll of 1 or 6 this creates a roll reference of 2, or 4 pointing at their respective nested rolls causing their containing toggleable section to be shown if their roll reference is created or remain hidden otherwise.

$[[$[[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]]

Related Pages