< 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.
ChoiceSelect a random choice from a group of options:
Weighted ChoiceAssign probabilities to choice selection:The weather was (sad | gloomy [2] | depressed[4]). -> "The weather was depressed." AssignmentBasic 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 Inline AssignmentInline assignments allow one to easily set a variable, output it, and refer to it later:Jane was from [$place=(New York | Berlin | Shanghai)]. TransformsTransforms 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? Sequence TransformsSequences 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"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"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" |