Documentation version 1.0 , 2009-11-21
Logic dependent commands: $If{}, $Break{}, $Exclude{}
All of the commands above can be used to alter the result
depending on a logical (= Boolean ; true/false) expression.
They are usually combined with the logical comparison commands $And{}, $Or{}, $Not{}, $>{}, $>={}, $<{}, $<={}, $=={}, $!={}.
(see tutorial 1)
The $If{} command simply outputs one of two alternating
strings depending on the Boolean value of its first parameter. If it is true
then the first string is given, else the second one. It will usually be
combined with variables containing random numbers, or values
derived from the system using either global variables or the $RPS{} command. While it is possible to construct
some branching
using the If{} command,
it is often simpler to use the $CaseOf{} command (see tutorial
2).
Example 1:
SCRIPT |
PREVIEW-RESULT |
$NewVar{opNr,integer,1,$Random{2,10}} At this table sit ten dwarves discussing how to deal with a gang of elves. Their leader suggests to attack them at nightfall. "Who agrees?", he asks, and $Var{opNr} dwarves nod eagerly. $If{$>{opNr,5},<"Well, that's decided then.">,<"Am I surrounded by cowards?!">} |
At this table sit ten dwarves discussing how to deal with a gang of elves. Their leader suggests to attack them at nightfall. "Who agrees?", he asks, and 2 dwarves nod eagerly. "Am I surrounded by cowards?!" or At this table sit ten dwarves discussing how to deal with a gang of elves. Their leader suggests to attack them at nightfall. "Who agrees?", he asks, and 8 dwarves nod eagerly. "Well, that's decided then." |
Example 2:
SCRIPT |
PREVIEW-RESULT |
"This is MY realm!" the dwarven bartender exclaims angrily as he denies the tall elf his drink. $If{$>{$RPS{SIZE},7},<"Such a big place for such a small guy!>,<What a little realm indeed.>}" snaps the elf back before leaving. |
when generated in “large” taverns: "This is MY realm!" the dwarven bartender exclaims angrily as he denies the tall elf his drink. "Such a big place for such a small guy!" snaps the elf back before leaving.
or when used in “small” taverns: "This is MY realm!" the dwarven bartender exclaims angrily as he denies the tall elf his drink. What a little realm indeed." snaps the elf back before leaving. |
Example 3:
SCRIPT |
PREVIEW-RESULT |
"Now, mage, tell me if it is safe to eat here", demands the fat noble man from his skinny companion. $If{$>{magic,3},<"I sense magical vibrations.">,<"I can't sense any magic here.">} |
If the global variable magic has counted magic: "Now, mage, tell me if it is safe to eat here", demands the fat noble man from his skinny companion. "I sense magical vibrations."
else: "Now, mage, tell me if it is safe to eat here", demands the fat noble man from his skinny companion. "I can't sense any magic here." |
The last example demonstrates the use and usefulness of global
variables. These variables are defined by the system (but can be
added) and should be increased by according datasets, e.g. datasets speaking of
used magic should increase the global magic variable
so that other datasets can determine their outcome based on other (selected)
descriptions of the tavern.
This gives many possibilities, but has two drawbacks: It relies on the fact
that the whole database sets global variables properly
(which makes later introduction of new variables tricky), and the variables are
evaluated when a dataset is selected. The latter means,
that if, f.e., 10 tables are occupied, and the 3rd
table-description checks against a global variable like magic, this
variable only contains
the information of the previous 2 tables, but not of the following 7. Thus,
global variables lack a certain amount of accuracy.
The $Break{} command allows to discarding all remaining
text of a description based on a condition. If its argument is true then
the rest of the text is simply ignored, but everything evaluated so far will be
returned.
Example 1:
SCRIPT |
PREVIEW-RESULT |
$NewVar{NrDice,integer,1,$Random{2,5}} As the magician lifts the cup, all eyes are fixed on the table, where $Var{NrDice} runes lie. The first and the second rune show both a dagger. $Break{$<{NrDice,3}} Also the third rune shows a dagger. $Break{$<{NrDice,4}} As does the fourth! $Break{$<{NrDice,5}} Indeed, all five show the same dagger! |
As the magician lifts the cup, all eyes are fixed on the table, where 3 runes lie. The first and the second rune show both a dagger. Also the third rune shows a dagger. or As the magician lifts the cup, all eyes are fixed on the table, where 4 runes lie. The first and the second rune show both a dagger. Also the third rune shows a dagger. As does the fourth! |
Finally, the $Exclude{} command
discards the whole dataset if its argument is true. The generation
algorithm continues as if the
specific dataset would have been refused by any of the other flag-filters and
tries to select a new one. The $Exclude{} command in
combination with global variables is a convenient way of ensuring that
only one selected description describes a unique person
like the bartender. Each dataset describing a bartender should increase
the relevant global variable and also has (usually at the
beginning) an $Exclude{}
command discriminating against that global variable as shown
below:
Example 1:
SCRIPT |
PREVIEW-RESULT |
$Exclude{$>{keeper,0}} $+{keeper,1} The bartender and owner of this tavern looks lazily around. |
Only if no other bartender-set has been selected so far: The bartender and owner of this tavern looks lazily around. |