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 "Roll Query/Nested"

From Roll20 Wiki

Jump to: navigation, search
(Undo revision 32421 by 1156216 (talk))
(Roll Query Troubleshooting: Nesting Queries)
Line 105: Line 105:
 
|}
 
|}
  
Here's a generic example of it in use. Note that starting from the second level of nesting, the <code>&amp;amp;</code> entity is being used to replace the <code>&</code> in HTML entities like <code>&amp;#124;</code>, <code>&amp;#125;</code> and <code>&amp;#44;</code>, meaning you have to use <code>&amp;amp;#124;</code>, <code>&amp;amp;#125;</code> and <code>&amp;amp;#44;</code> instead.
+
Starting from the second level of nesting, the <code>&amp;amp;</code> entity is being used to replace the <code>&</code> in <code>&amp;#124;</code>, <code>&amp;#125;</code> and <code>&amp;#44;</code>, meaning that you need to use <code>&amp;amp;#124;</code>, <code>&amp;amp;#125;</code> and <code>&amp;amp;#44;</code> instead. Subsequent "stacking" of ampersand for further levels of nesting (i.e: <code>&amp;amp;amp;#124;</code>) are possible:
 +
 
 +
{| class="wikitable"
 +
|-
 +
! Nesting Level !! Pipe !! Closing Brace !! Comma
 +
|-
 +
| 0 || <code>&#124;</code> || <code>&#125;</code> ||<code>&#44;</code>
 +
|-
 +
| 1 || <code>&amp;#124;</code> || <code>&amp;#125;</code> ||<code>&amp;#44;</code>
 +
|-
 +
| 2 || <code>&amp;amp;#124;</code> || <code>&amp;amp;#125;</code> ||<code>&amp;amp;#44;</code>
 +
|-
 +
| 3 || <code>&amp;amp;amp;#124;</code> || <code>&amp;amp;amp;#125;</code> ||<code>&amp;amp;amp;#44;</code>
 +
|-
 +
| 4 || ... || ... || ...
 +
|}
 +
 
 +
Here's a generic example of it in use.
  
 
<pre style="overflow:auto; width:auto;">?{Name of Query|
 
<pre style="overflow:auto; width:auto;">?{Name of Query|

Revision as of 08:32, 19 December 2022


Main Page: Roll Queries & Nesting

If a macro contains characters used in a Roll Query (like the closing curly brackets, vertical bars, and commas), it can result in undesired behaviour.

For example, say you want to create a dropdown menu which contains a roll query, like so:

?{Choose a Roll|
   STR,/roll 1d20 + @{STR} + ?{Bonus}|
   DEX,/roll 1d20 + @{DEX} + ?{Bonus}|
   CON,/roll 1d20 + @{CON} + ?{Bonus}}

The problem here is that the } character signals the end of a query, and Roll20 isn't smart enough to know that one query is nested inside another. So when that Bonus query is encountered, the }-bracket will cause the dropdown menu to break.

Commas and vertical lines (|) are also part of query syntax, so they can cause problems too.

The way to deal with this, is replace characters with their relevant HTML entities

Change only the needed characters. If you have a nested query, change only the characters in the nested query, not the outer query.

Here's the above example, with a nested dropdown:

?{Choose a Roll|
   STR,/roll 1d20 + @{STR} + ?{Bonus&#125; |
   DEX,/roll 1d20 + @{DEX} + ?{Bonus&#125; |
   CON,/roll 1d20 + @{CON} + ?{Bonus&#125; }

Contents

Roll Query Troubleshooting: NEVER REPLACE ATTRIBUTES

You'll notice in the above example, the attribute call wasn't changed. It's very important that you never replace the characters in calls (i.e. @{Attribute}, %{Ability}, #Macro).

Due to the order of operations, calls are parsed to their values before Roll Queries are executed. If you change characters to their HTML entities, the call will be broken and the macro will fail.

  • Never, ever, do this: @{target&#124;token_name&#125;.
  • Always leave calls alone: @{target|token_name}

Roll Query Troubleshooting: Call Values

If you call an Attribute, Ability, or Macro, the contents are expanded before resolving. This means if your macro calls another macro, and that macro has a query syntax character (comma, pipe, closing curly bracket), it will cause the macro to fail.

So you need to locate and replace all problematic characters within the values of any Attributes, Abilities or Macros.

Once you've done those, those values now contain HTML entities, the affected calls probably no longer work outside of your Roll Query. So, it's usually best to just directly insert these values into your Roll Query, replacing their call.

Here's an example of a query that calls macros.

?{Choose an Attack|
   Melee,#Melee-attack |
   Ranged,#Ranged-attack |
   Psychic,#Psychic-attack }

At first glance, this looks straight forward. But what if those macros looked like this:

Melee-attack: /roll 1d20+ @{STR} + ?{Bonus|0}
Ranged-attack: /roll 1d20+ @{DEX} + ?{Bonus|0}
Psychic-attack: /roll 1d20+ @{WIS} + ?{Bonus|0}

On their own those macros work fine, but when you try to use them in the dropdown query, that query fails. To get them to work, you'd need to change that bonus query, like so:

Melee-attack: /roll 1d20+ @{STR} + ?{Bonus|0&#125;
Ranged-attack: /roll 1d20+ @{DEX} + ?{Bonus|0&#125;
Psychic-attack: /roll 1d20+ @{WIS} + ?{Bonus|0&#125;

That fixes the roll query, but the macros no longer work properly on their own - the Bonus query isn't recognized.

So you are best off leaving the macros alone, and copying their contents to your dropdown:

?{Choose an Attack|
   Melee,/roll 1d20+ @{STR} + ?{Bonus&#124;0&#125; |
   Ranged,/roll 1d20+ @{DEX} + ?{Bonus&#124;0&#125; |
   Psychic,/roll 1d20+ @{WIS} + ?{Bonus&#124;0&#125; }

And now your query works. Whenever you have an Ability or Macro call in a query, you'll often find it's better just to copy the contents over to to your query and edit in place, as shown above.

Roll Query Troubleshooting: Simplify Where Possible

It's a good idea to separate out elements that are repeated within each 'row' of the query. For instance, that last query could be rewritten as

/roll 1d20+ ?{Choose an Attack|
   Melee,@{STR} |
   Ranged,@{DEX} |
   Psychic,@{WIS} } + ?{Bonus|0}

The /roll 1d20+ part is common to each rows, so you simplify the macro by moving it out. The + ?{Bonus|0} part is common to all, and can also be moved out of the query, thus avoiding the need for HTML substitution completely.

You won't be able to simplify all advanced queries in this way, but when you can, it makes the macro a lot simpler.

Roll Query Troubleshooting: Collections Macros

You normally store queries in Macros, saved under the l Collections-tab of the Sidebar. Unfortunately, whenever you open a macro stored there, Roll20 parses the macro and this causes HTML entities to be converted to the characters their represent. This breaks your carefully created macro.

So, if you place macros containing HTML entities there, it's a good idea to store a backup somewhere. This behaviour doesn't happen with Abilities, so many people create a Macro Character Sheet, for storing such macros safely as abilities.

Roll Query Troubleshooting: Nesting Queries

You can achieve further levels of nesting by "stacking" ampersand & HTML entities:

Character Replacement
& &amp;

Starting from the second level of nesting, the &amp; entity is being used to replace the & in &#124;, &#125; and &#44;, meaning that you need to use &amp;#124;, &amp;#125; and &amp;#44; instead. Subsequent "stacking" of ampersand for further levels of nesting (i.e: &amp;amp;#124;) are possible:

Nesting Level Pipe Closing Brace Comma
0 | } ,
1 &#124; &#125; &#44;
2 &amp;#124; &amp;#125; &amp;#44;
3 &amp;amp;#124; &amp;amp;#125; &amp;amp;#44;
4 ... ... ...

Here's a generic example of it in use.

?{Name of Query|
   Label 1, ?{value1&#124;
      Label 1A&#44; ?{value1A&amp;#124;
         Label 1Ai&amp;#44; value1Ai &amp;#124;
         Label 1Aii&amp;#44; value1Aii
      &amp;#125; &#124;
      
      Label 1B&#44; ?{value1B&amp;#124;
         Label 1Bi&amp;#44; value1Bi &amp;#124;
         Label 1Bii&amp;#44; value1Bii
      &amp;#125;
   &#125; |

   Label 2, ?{value2&#124;value2&#125; 
}