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
m
m
Line 1: Line 1:
<noinclude>{{revdate}}{{main|Roll Query}}</noinclude>  
+
<noinclude>{{revdate}}
 +
 
 +
{{notebox| Go to '''[[Roll Query]]''' for the full documentation on all types types of nesting }}
 +
 
 +
{{main|Roll Query}}</noinclude>  
 
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.  
 
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.  
 
<noinclude>{{NavMacroDocs}}</noinclude>  
 
<noinclude>{{NavMacroDocs}}</noinclude>  
Line 29: Line 33:
 
Due to the [[Order_of_Operations|order of operations]], <u>calls</u> 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.
 
Due to the [[Order_of_Operations|order of operations]], <u>calls</u> 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:''' <code>@{target&amp;#124;token_name&amp;#125;</code>.  
+
* '''Never, ever, do this:''' <code>@{target&amp;#124;token_name&amp;#125;</code>.  
Always leave calls alone: <code>@{target|token_name}</code>
+
* Always leave calls alone: <code>@{target|token_name}</code>
  
 
====Roll Query Troubleshooting: Call Values ====
 
====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 <i>that</i> macro has a query syntax character (comma, pipe, closing curly bracket), it will cause the macro to fail.
+
If you call an [[Character#Attribute|Attribute]], [[Character#Abilities|Ability]], or [[Macro]], the contents are expanded before resolving. This means if your macro calls another macro, and <i>that</i> 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.
 
So you need to locate and replace all problematic characters within the ''values'' of any Attributes, Abilities or Macros.
Line 88: Line 92:
 
You normally store queries in Macros, saved under the {{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.  
 
You normally store queries in Macros, saved under the {{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 [[Journal#Abilities|Abilities]], so many people create a {{fpl|5924364/ Macro Character Sheet}}, for storing such macros safely as abilities.
+
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 [[Journal#Abilities|Abilities]], so many people create a [[Macro Character Sheet]], for storing such macros safely as abilities.
  
 
====Roll Query Troubleshooting: Nesting Queries====
 
====Roll Query Troubleshooting: Nesting Queries====

Revision as of 14:45, 30 November 2021


Main Page: Roll Query

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" HTML entities:

Character Replacement
& &amp;

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