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)
m
 
(7 intermediate revisions by 2 users not shown)
Line 2: Line 2:
 
|name=ExtendedExpressions
 
|name=ExtendedExpressions
 
|author={{user profile|503018|manveti}}
 
|author={{user profile|503018|manveti}}
|version=0.1
+
|version=0.5
|lastmodified=2015-05-24}}
+
|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|inline roll]] tooltips as complete as possible.
  
It is recommended that this script be used in conjunction with the [[Script:CommandShell|CommandShell]] module, which will improve output formatting and command discovery.
+
It is recommended that this script be used in conjunction with the [[Script:CommandShell|CommandShell]] module, which will improve output formatting and command discovery, as well as enabling the execution of '''CommandShell'''-aware commands.
  
  
Line 68: Line 68:
 
|-
 
|-
 
|<nowiki>x = y</nowiki>||Equality
 
|<nowiki>x = y</nowiki>||Equality
 +
|-
 +
|<nowiki>x == y</nowiki>||Equality (synonym for =)
 
|-
 
|-
 
|<nowiki>x != y</nowiki>||Inequality
 
|<nowiki>x != y</nowiki>||Inequality
Line 94: Line 96:
 
|-
 
|-
 
|<nowiki>x ? y : z</nowiki>||Conditional evaluation
 
|<nowiki>x ? y : z</nowiki>||Conditional evaluation
 +
|}
 +
 +
=== Functions ===
 +
{|
 +
|-
 +
|<nowiki>abs(x)</nowiki>||Absolute value
 +
|-
 +
|<nowiki>ceil(x)</nowiki>||Round up to integer value
 +
|-
 +
|<nowiki>floor(x)</nowiki>||Round down to integer value
 +
|-
 +
|<nowiki>round(x)</nowiki>||Round to nearest integer value
 +
|-
 +
|<nowiki>max(x, y, ...)</nowiki>||Greatest of x, y, ...
 +
|-
 +
|<nowiki>min(x, y, ...)</nowiki>||Least of x, y, ...
 
|}
 
|}
  
Line 114: Line 132:
 
:<nowiki>!extend `1d6[foo]+1d6[bar]+${(1d2-1 ? "foo" : "bar")}`</nowiki>
 
:<nowiki>!extend `1d6[foo]+1d6[bar]+${(1d2-1 ? "foo" : "bar")}`</nowiki>
 
::Internally rolls 1d2-1, then submits a command like <nowiki>"[[3+1d6[bar]+3]]"</nowiki> or <nowiki>"[[1d6[foo]+2+2]]"</nowiki>.
 
::Internally rolls 1d2-1, then submits a command like <nowiki>"[[3+1d6[bar]+3]]"</nowiki> or <nowiki>"[[1d6[foo]+2+2]]"</nowiki>.
 +
:<nowiki>!extend `max(1d2[foo], 1d3[bar], 1d4[baz])`: `${foo}`, `${bar}`, `${baz}`</nowiki>
 +
::Internally rolls three dice of different sizes, then displays the largest of the three rolls along with the values of all three.
  
 
=== 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 <nowiki>==</nowiki> 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.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}}
 +
[[Category:Discontinued API Scripts]]

Latest revision as of 12:41, 12 April 2021

API ScriptAuthor: manveti
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, as well as enabling the execution of CommandShell-aware commands.


Contents

[edit] Syntax

!exroll <command>
!extend <command>
Formally:

S

→ exroll string

S

→ extend string

[edit] 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

[edit] 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, ...

[edit] 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.

[edit] 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.

[edit] Changelog

v0.5 (2015-06-11)

  • Add support for executing CommandShell-aware API commands


v0.4 (2015-06-03)

  • Add == operator and several functions. Improve error reporting.


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