Documentation
Introduction
Tablescript is a simple scripting language with built-in support for random content generation. The current version allows tables - arrays of elements selected at random when a table is called like a function - and dice literals (e.g. 3d6+5).
The language grew out of a desire to have more random content more readily available when running role-playing games. For instance, it’s jarring to the players and the narrative when the characters decide to visit a town that the GM hasn’t prepared. With Tablescript (and a random town generation script), a GM can quickly produce enough narrative colour to maintain the illusion that the game world is alive and complete.
Getting Started
Tablescript has standard types (number
, string
, boolean
, object
, array
, undefined
), first class functions
, and first class tables
.
A simple script might look like this:
(Tablescript has several built-in functions - print()
is one of them.)
Tablescript has two types of tables: a choice
where each entry has the same probability, and a table
where each entry has custom probabilities.
A simple choice
table might look like this:
To use the table, call it like you would a function:
You can make complex tables by adding scripting elements:
Tables (table
) can also have entries with different probabilities:
Both tables and choices can have arbitrary expressions as entries:
Tablescript has only expressions - no statements. Every expression evaluates to a value. If/else expressions are evaluated the same way math is:
Functions automatically return the last value - there is no return
statement:
Tablescript also has a conditional operator, so that example could be written much more succinctly: