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 "Script:Extended Expressions"

From Roll20 Wiki

Jump to: navigation, search
(Fix example output to line up with input)
(Update for v0.2.)
Line 2: Line 2:
 
|name=ExtendedExpressions
 
|name=ExtendedExpressions
 
|author={{user profile|503018|manveti}}
 
|author={{user profile|503018|manveti}}
|version=0.1
+
|version=0.2
|lastmodified=2015-05-24}}
+
|lastmodified=2015-05-26}}
  
 
'''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 116: Line 116:
  
 
=== Changelog ===
 
=== Changelog ===
 +
{{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 22:57, 26 May 2015

API ScriptAuthor: manveti
Version: 0.2
Last Modified: 2015-05-26
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 "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]]".

Changelog

v0.2 (2015-05-26)

  • Add handling of roll templates


v0.1 (2015-05-24)

  • Initial release