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
(Created page with "{{revdate}} If 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 contr...")
 
m (formatting)
Line 1: Line 1:
{{revdate}}
+
{{revdate}}{{NavMacroDocs}}
If 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 <code>[[0</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>(without the closing <code><nowiki>]]</nowiki></code>) ensures that.
 
==Query controlled toggles==
 
==Query controlled toggles==
 
===Simple single section===
 
===Simple single section===
Line 6: Line 6:
 
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>?{Section|Show,|Hide,[[0}</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 style="overflow:auto;white-space:nowrap;">&{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. 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.
 
===Multiple sections===
 
===Multiple sections===
Line 14: Line 14:
 
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
<pre style="overflow:auto;white-space:nowrap;" >[[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]]}} ]]</pre>
+
<pre>[[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]]}} ]]</pre>
  
 
If you want to have a toggleable section that doesn't include any rolls you can use a reference of <code>-1</code> outside of the template fields but still inside the encompassing roll. Such as
 
If you want to have a toggleable section that doesn't include any rolls you can use a reference of <code>-1</code> outside of the template fields but still inside the encompassing roll. Such as
<pre style="overflow:auto;white-space:nowrap;">[[0 ?{Text only section|Show,$|Hide,+}[[-1]] {{Text Only Section}} ]]</pre>
+
<pre>[[0 ?{Text only section|Show,$|Hide,+}[[-1]] {{Text Only Section}} ]]</pre>
  
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 style="overflow:auto;white-space:nowrap;">[[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>
 +
 
 +
==Related Pages==
 +
* [[Roll Templates]]
 +
* [[Reusing Rolls]]
 +
* [[Complete_Guide_to_Macros_%26_Rolls#Advanced|Complete Guide to Macros: Advanced Tricks]]
 
[[Category:Macros]]
 
[[Category:Macros]]
 
[[Category:Roll Templates]]
 
[[Category:Roll Templates]]

Revision as of 06:31, 18 March 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(without the closing ]]) ensures that.

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. Secondly you cannot reuse rolls since trying to reuse a roll inside another tends to break the roll which prevents it from hiding the template fields.

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]]}} ]]

Related Pages