RiScript

< RiTa index

RiScript is a writer-oriented plain-text scripting language integrated in RiTa. RiScript statements, the basics of which are described below, can be included in any grammar, or executed directly by calling RiTa.evaluate(). Fragments of writing can be abitrarily transformed, at runtime, by using the provided transforms, or by specifying your own bespoke ones.

Choice

Select a random choice from a group of options:
The weather was (sad | gloomy | depressed).  ->  "The weather was gloomy."

I'm (very | super | really) glad to \
((meet | know) you | learn about you). -> "I'm very glad to know you."

Weighted Choice

Assign probabilities to choice selection:
The weather was (sad | gloomy [2] | depressed[4]).  ->  "The weather was depressed." 

Assignment

Basic assignments do not have output, they simply create or update a variable to be used elsewhere (variables in JavaScript may also be used when passed in via the scripts 'context')
$desc=wet and cold
The weather was $desc -> "The weather was wet and cold"

Inline Assignment

Inline assignments allow one to easily set a variable, output it, and refer to it later:
Jane was from [$place=(New York | Berlin | Shanghai)].
$place is cold and wet.
-> "Jane was from Berlin. Berlin is cold and wet."

$place=(New York | Berlin | Shanghai)
$place is cold and wet in winter.
-> "Berlin is cold and wet in the winter."

In [$place=(New York | Berlin | Shanghai)] it is cold and wet in winter.
-> "In Berlin it is cold and wet in the winter."

Transforms

Transforms allow for the transformation of variables, choices and raw text at runtime. RiScript provides a number of useful transforms, including pluralize(), capitalize() and articlize(), which can be nested to create complex expressions. User-defined transforms can be easily added using RiTa.addTransform() or by simply passing a transform function as part of a script's 'context'.
How many (tooth | menu | child).pluralize() do you have?
How many (tooth | menu | child).pluralize().toUpper() do you have?

He grew up to be $animal.articlize().
He grew up to be (anteater).articlize().
He grew up to be (anteater).articlize().myCustomTransform().

Sequence Transforms

Sequences allow one to control how Choice options are selected over multiple uses in the same script or multiple iterations of a script.

Use the seq() transform to output the Choice options in a linear sequence:
The weather was (sad | gloomy | depressed).seq()
0) "The weather was sad" 
1) "The weather was gloomy"
2) "The weather was depressed"
3) "The weather was sad"
...
Use the rseq() transform for a randomized, non-repeating sequence (each choice will be selected before any repeat):
The weather was (sad | gloomy | depressed).rseq()
0) "The weather was depressed"
1) "The weather was gloomy"
2) "The weather was depressed"
3) "The weather was sad"
4) "The weather was gloomy"
...
Use the norep() transform if you want to ensure that outputs do not repeat:
The weather was (sad | gloomy | depressed).norep()
0) "The weather was depressed" 
1) "The weather was gloomy"
2) "The weather was depressed"
3) "The weather was sad"
4) "The weather was gloomy"
...