Starting in version 2.2, Ramus includes a little scripting language. It's kind of clunky and doesn't have a name yet. The goal was to make something easy to use while keeping Ramus not too large. Here's a small sample:
<s>set a 1</s> <s>echo $a</s>
<s>test $a = 1</s>
<s>iftrue echo Is too!</s>
<s>iffalse echo Is not!</s>
Each command is contained in an <s>
tag, and can appear anywhere in a story fragment; the command's output will replace its text at that point. Be careful where you put an include
command.
(Note: you can still use an <s>
tag for its intended purpose by giving it an attribute, for example some dummy class.)
Speaking of which, each command is made of words separated by whitespace. The first word says what built-in function to call, and the rest are passed to it as arguments:
command (arg) (arg) ...
Before calling the function, several conversions are performed:
#t
and #f
become the boolean values true
and false
, respectively.
Beware that few checks are performed on commands. Results may be silently wrong. This is so the story keeps working instead of stopping the player cold. Check the browser console for warnings to make sure.
Scripts should work in any browser released from 2011 onward.
As of version 2.2, there are six built-in functions in Ramus (see below for later additions):
Use set
to, well, set variables:
<s>set a 10</s> <s>set b $a</s>
With echo
you can display their values to the player:
<s>echo Right now, a is $a and b is $b</s>
You can display a whole other fragment with include
:
<s>set choice left-path</s> <s>include $choice</s>
Included fragments are scored, marked as visited and parsed for scripts, but their title attribute (if any) is ignored.
test
checks if a condition is true and sets an internal flag accordingly:
<s>test $b = 10</s>
test
doesn't support full arithmetic expressions, but only a few checks and comparisons.
Last but not least, iftrue
and iffalse
look at the internal flag set by test
and run the rest of their arguments as a command, but only if the flag is true or false, respectively:
<s>iftrue echo Is too!</s> <s>iffalse echo Is not!</s>
If test
couldn't perform the check for some reason, neither branch is taken.
The general syntax of test
is as follows:
test operand1 comparison operand2
Where comparison
can be one of =
(or ==
), !=
, <
, <=
, >
or >=
. Note that you can't actually write a literal < or > in HTML code, it has to be < and > instead, respectively.
Apart from that, there's one other form:
test visited fragment-id
which does just what it seems to. The fragment id doesn't start with a hash sign, but can be stored in a variable just fine.
As of version 2.3, there are three new functions:
random
stores a pseudo-random floating point value from the [0, 1) interval in the given variable:
<s>random d</s> <s>echo $d</s>
incr
and decr
increase or decrease a numeric variable with the given step (1 by default):
<s>incr a 2</s> <s>decr a</s>
If the variable doesn't exist already, it's initialized to 0 first.