Script:Extended Expressions
From Roll20 Wiki
Version: 0.1
Last Modified: 2015-05-24
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 | 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 |
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 "[[12]], miss" or "[[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]]".
Changelog
v0.1 (2015-05-24)
- Initial release