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(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