Difference between revisions of "Script:Extended Expressions"
From Roll20 Wiki
(Update to v0.4) |
(Update for v0.5) |
||
Line 2: | Line 2: | ||
|name=ExtendedExpressions | |name=ExtendedExpressions | ||
|author={{user profile|503018|manveti}} | |author={{user profile|503018|manveti}} | ||
− | |version=0. | + | |version=0.5 |
− | |lastmodified=2015-06- | + | |lastmodified=2015-06-11}} |
'''ExtendedExpressions''' extends the built-in expression syntax to allow multiple references to a single roll within an expression, advanced bitwise, logical, and arithmetic operations, and more. Expressions are evaluated internally where necessary, but care is taken to pass as much of each expression as possible along to the builtin expression evaluator in order to make inline roll tooltips as complete as possible. | '''ExtendedExpressions''' extends the built-in expression syntax to allow multiple references to a single roll within an expression, advanced bitwise, logical, and arithmetic operations, and more. Expressions are evaluated internally where necessary, but care is taken to pass as much of each expression as possible along to the builtin expression evaluator in order to make inline roll tooltips as complete as possible. | ||
Line 136: | Line 136: | ||
=== Changelog === | === Changelog === | ||
+ | {{changelog version|0.5|2015-06-11|* Add support for executing CommandShell-aware API commands}} | ||
{{changelog version|0.4|2015-06-03|* Add == operator and several functions. Improve error reporting.}} | {{changelog version|0.4|2015-06-03|* Add == operator and several functions. Improve error reporting.}} | ||
{{changelog version|0.3|2015-05-26|* Fix error reporting, non-dice !exroll commands, and a bug using variables in particularly complicated expressions}} | {{changelog version|0.3|2015-05-26|* Fix error reporting, non-dice !exroll commands, and a bug using variables in particularly complicated expressions}} | ||
{{changelog version|0.2|2015-05-26|* Add handling of roll templates}} | {{changelog version|0.2|2015-05-26|* Add handling of roll templates}} | ||
{{changelog version|0.1|2015-05-24|* Initial release}} | {{changelog version|0.1|2015-05-24|* Initial release}} |
Revision as of 05:55, 12 June 2015
Version: 0.5
Last Modified: 2015-06-11
Code: ExtendedExpressions
Dependencies: None
Conflicts: None
ExtendedExpressions extends the built-in expression syntax to allow multiple references to a single roll within an expression, advanced bitwise, logical, and arithmetic operations, and more. Expressions are evaluated internally where necessary, but care is taken to pass as much of each expression as possible along to the builtin expression evaluator in order to make inline roll tooltips as complete as possible.
It is recommended that this script be used in conjunction with the CommandShell module, which will improve output formatting and command discovery.
Contents |
Syntax
!exroll <command>
!extend <command>
Formally:
S
→ exroll string
S
→ extend string
Operators
The following operators are supported, in decreasing precedence order:
x ** y | Exponentiation |
!x | Logical NOT |
~x | Bitwise NOT |
-x | Negation |
x * y | Multiplication |
x / y | Division |
x % y | Modulus |
x + y | Addition |
x - y | Subtraction |
x << y | Left shift |
x >> y | Right shift |
x >= y | Comparison (greater than or equal) |
x > y | Comparison (strictly greater than) |
x < y | Comparison (strictly less than) |
x <= y | Comparison (less than or equal) |
x = y | Equality |
x == y | Equality (synonym for =) |
x != y | Inequality |
x & y | Bitwise AND |
x ^ y | Bitwise XOR |
x | y | Bitwise OR |
x && y | Logical AND |
x || y | Logical OR |
x ? y : z | Conditional evaluation |
Functions
abs(x) | Absolute value |
ceil(x) | Round up to integer value |
floor(x) | Round down to integer value |
round(x) | Round to nearest integer value |
max(x, y, ...) | Greatest of x, y, ... |
min(x, y, ...) | Least of x, y, ... |
Additional Syntax
"string" | String literal. Expressions which evaluate to strings will be placed inline directly rather than as inline rolls. |
exp[label] | Apply label to the preceeding expression for later reference. Precedence is higher than every operator except "d" (the dice operator). Use parentheses to label the size of a die rather than the result of the roll (e.g. "1d(4[diesize])"). |
${label} | Substitute in the value of the referenced expression. Label can be either an identifier or a string expression. |
Examples
- !exroll 1t["table-number-" + 1d6] weather
- Internally rolls 1d6, concatenates it with the string "table-number-", and submits a command of the form "/roll 1t[table-number-3] weather".
- !extend Attack: `(1d20+7)[tohit]`, `(${tohit}>=15 ? "hit for [[1d6]]" : "miss")`
- Internally rolls 1d20+7, compares the result against 15, and submits a command like "Attack: [[12]], miss" or "Attack: [[19]], hit for [[1d6]]".
- !extend `1d6[foo]+1d6[bar]+${(1d2-1 ? "foo" : "bar")}`
- Internally rolls 1d2-1, then submits a command like "[[3+1d6[bar]+3]]" or "[[1d6[foo]+2+2]]".
- !extend `max(1d2[foo], 1d3[bar], 1d4[baz])`: `${foo}`, `${bar}`, `${baz}`
- Internally rolls three dice of different sizes, then displays the largest of the three rolls along with the values of all three.
Changelog
v0.5 (2015-06-11)
- Add support for executing CommandShell-aware API commands
v0.4 (2015-06-03)
{{{3}}}
v0.3 (2015-05-26)
- Fix error reporting, non-dice !exroll commands, and a bug using variables in particularly complicated expressions
v0.2 (2015-05-26)
- Add handling of roll templates
v0.1 (2015-05-24)
- Initial release