Difference between revisions of "Order of Operations"
From Roll20 Wiki
Andreas J. (Talk | contribs) m |
Andreas J. (Talk | contribs) m |
||
Line 3: | Line 3: | ||
{{NavMacroDocs}}'''Order of Operations''' here refers to the order in which Roll20's dice engine processes the different dice syntax and [[macros]], which is useful to know when creating more complex macros. Normal [https://www.basic-mathematics.com/order-of-operations.html Math Order of Operations] is processed towards the end of the process. | {{NavMacroDocs}}'''Order of Operations''' here refers to the order in which Roll20's dice engine processes the different dice syntax and [[macros]], which is useful to know when creating more complex macros. Normal [https://www.basic-mathematics.com/order-of-operations.html Math Order of Operations] is processed towards the end of the process. | ||
− | </noinclude>While the Roll20 dice engine does support basic math and [[Dice_Reference#Math_Operators_and_Functions|functions]] such as <code>floor()</code> and <code>ceil()</code>, it is first and foremost a dice engine, and so it has its own order of operations. This means that putting parentheses inside of your dice formula will not always affect the outcome of the roll (for example, you can't force a variable to be interpreted before a macro). Here is the Roll20 Order of Operations: | + | </noinclude>While the Roll20 dice engine does support basic math and [[Dice_Reference#Math_Operators_and_Functions|math functions]] such as <code>floor()</code> and <code>ceil()</code>, it is first and foremost a dice engine, and so it has its own order of operations. This means that putting parentheses inside of your dice formula will not always affect the outcome of the roll (for example, you can't force a variable to be interpreted before a macro). Here is the Roll20 Order of Operations: |
:1. '''[[Character#Abilities|Abilities]]''' are expanded (meaning the definition of the ability is placed in the formula anywhere that ability appears; e.g. <code>%{character name|ability_name}</code> becomes <code>/r 1d4</code>). | :1. '''[[Character#Abilities|Abilities]]''' are expanded (meaning the definition of the ability is placed in the formula anywhere that ability appears; e.g. <code>%{character name|ability_name}</code> becomes <code>/r 1d4</code>). |
Latest revision as of 10:42, 17 January 2022
Page Updated: 2022-01-17 |
This article is a stub. |
Main Page: Complete Guide to Macros & Rolls
Macro Creation
- Complete Guide to Macros & Rolls
- q Text Chat
- Dice Reference
- Order of Operations
- Macros
- Token Reference
- Character Reference
- Roll Templates
- Roll Table
Advanced
- Formatting
- HTML Replacement
- Chat Menus
- Hidden Rolls
- Advanced Macro Tips
- API Commands
- Char Sheet Creation
Misc.
Order of Operations here refers to the order in which Roll20's dice engine processes the different dice syntax and macros, which is useful to know when creating more complex macros. Normal Math Order of Operations is processed towards the end of the process.
While the Roll20 dice engine does support basic math and math functions such as floor()
and ceil()
, it is first and foremost a dice engine, and so it has its own order of operations. This means that putting parentheses inside of your dice formula will not always affect the outcome of the roll (for example, you can't force a variable to be interpreted before a macro). Here is the Roll20 Order of Operations:
- 1. Abilities are expanded (meaning the definition of the ability is placed in the formula anywhere that ability appears; e.g.
%{character name|ability_name}
becomes/r 1d4
). - 2. Macros are expanded (e.g.
#macro-name
becomes/r 1d4
). - 3. Attribute calls are resolved. (e.g.
@{attribute_name}
becomes4
) - 4. Steps 1-3 are repeated up to 99 levels deep, or there are no longer any expansions required.
- 5. Roll queries are executed up to 99 levels deep (the player making the roll is asked to provide a value for each query, and that value is substituted in where the roll query appears in the formula).
- 5b. HTML Entities within roll queries are parsed once after each roll query (e.g.
}
becomes}
, but&#125;
becomes}
)
- 5b. HTML Entities within roll queries are parsed once after each roll query (e.g.
- 6. Inline rolls are executed, starting with the most deeply nested inline roll working upward. The overall result of the inline roll is substituted in place where it appeared in the formula.
- 7. The remaining roll is executed: first, dice are rolled for any dice (e.g.
2d6
is rolled; including any special dice such as dropped or exploding), then the result of that roll is substituted into the formula.
- 8. Mathematical functions like
floor()
andceil()
are executed.
- 9. The entire remaining formula is evaluated, including observing proper Math Order of Operations (parentheses first, then multiplication/division, then addition/subtraction).
- 10. HTML Entities are processed once more
- (NEW)Custom Roll Parsing comes before or after HTML entities are processed. (needs verifying)
- 11. The message is sent to q Text Chat as well as the API sandbox.
Thank you to Scott C. for additional testing in this matter!
[edit] Examples
(todo)