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

Toggleable template fields

From Roll20 Wiki

Jump to: navigation, search

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

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=$[[0]] 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=$[[0]] One!}} ]]] [[[0 [[0]] {{d6=$[[0]] Six!}} {{Bonus d6=$[[5]]}} ]]] [[d6 Bonus]]

Progressive Variant

Thus far each section has used distinct rolls to seperate the sections to be shown. But by using nested rolls and having sections at each level it is possible to reveal or hide sections up to or beyond a specific section instead of just one. In this example a 1d4 will show between 0 and 3 toggleable sections

&{template:default} $[[$[[1]]]] [[[ [[ 6- [[1d4]] ]] ]]]  {{Roll=$[[0]]}} [[0 {{First}} [[0 {{Second}} [[0 {{Third}} [[0]] ]] ]] ]] {{name=Progressive TTF}}

Related Pages