Documentation
Types
Tablescript has standard JavaScript-y types including strings, numbers, booleans, and functions. It also has built-in support for table types and dice literals for content generation.
String
Tablescript supports 'single-quoted strings'
and "double-quoted strings"
. These work like they do in JavaScript and support escaping characters if necessary.
Template Strings
Tablescript also supports `back-tick template strings`
for interpolation. Inside a template string, inject arbitrary Tablescript expressions using ${ ... }
.
Operations
Strings can be indexed (starting with 0):
Strings can be reverse-indexed (starting with -1):
Strings indexed beyond the bounds are undefined:
Strings can be concatenated:
…though it’s better to use template strings:
Strings can be multiplied:
Number
Tablescript supports Javascript-y numbers like integers and floats.
You can convert from string to number with the int()
built-in.
Tablescript does not support scientific or engineering notation. If you need those types of numbers, Tablescript might not be the right tool for the job.
Boolean
Tablescript supports boolean values: either true
or false
.
Array
Tablescript supports arrays of values and a variety of operations on those arrays.
Methods
Arrays have built-in methods for manipulating them. Call array methods like this:
append(i)
Returns a new array with i
appended to the end of the old array.
choose()
Returns a randomly selected entry from the array.
countBy(f)
Returns an object where the keys are the result of calling f(entry)
for each array entry, and the values are the count of the number of array entries that return the same key.
each(f)
Calls f(entry)
for each array entry, and returns the value of the last call.
every(f)
Returns true
if for every array entry, f(entry)
returns true.
some(f)
Returns true
if for at least 1 array entry, f(entry)
returns true.
filter
includes
indexOf
find
findIndex
length
join
map
reduce
reverse
slice
sort
unique
Object
Function
Table
Dice Literals
Tablescript supports dice literals in mathematical expressions. For example:
The dice format looks like this:
<count>d<sides><modifiers>
where count
is the optional number of dice to roll, sides
is the number of theoretical sides on the die, and modifiers
is a combination of the following:
d
- drop the lowest died1
,d2
, etc. - drop a number of lowest dicedl1
,dl2
, etc. - also drop a number of lowest dicedh1
,dh2
, etc. - drop a number of highest dicek
- keep the highest diek1
,k2
, etc. - keep a number of highest dicekh1
,kh2
, etc. - also keep a number of highest dicekl1
,kl2
, etc. - keep a number of lowest dicer1
- re-roll 1sr<3
- re-roll 1s and 2sr>19
- re-roll 20s (on a d20 for instance)
Other examples include:
d6
(count
is optional)3d6
4d6d
(4d6 drop the lowest)2d20dr<3
(2 d20s, re-roll 1s and 2s, drop the lowest result)
sides
can also be F
to roll Fate/Fudge dice.
dF
4dF
Roll20-style formats are largely supported. For more details, see the Roll20 documentation.
Undefined
Uninitialized variables are undefined
.