DEdit – Database Editor

Documentation version 1.0 , 2009-11-21


Command examples

Simple varying output commands: $OneOf{}, $Random{}, $Direct{},  $CaseOf{}

All of the commands above can be used to create alternating text output with simple random choice. They are the ‘basic’
commands which can be used without any programming skill.

 

Example 1:

SCRIPT

PREVIEW-RESULT

$OneOf{<first>,<second>,<third>}

$OneOf{<first>,<>}

$OneOf{<first>,< >}

$OneOf{<first>,<second>,<third>}

third

first

 

second

The $OneOf{} command can have an arbitrary number of parameters, all separated by comma and – as they are string values –

Included in < > brackets. Each time the script is evaluated, one of the parameters is randomly chosen and used. However, note that

a completely empty string (null-string, or <>) is ignored by the command and will never be chosen.
(This is reasonable, because strings in the command can themselves contain script-commands, and some of them might return a
“null”-result. In such a case, one wants to pick another choice...)
Please note the difference between the “empty” string in the second and the third line. While the second line contains a real (and
thus ignored) null-string, the third line contains a valid string containing a space-character. This is a valid choice! The next
examples shows a typical use of the $OneOf{} command:

Example 2:

SCRIPT

PREVIEW-RESULT

The elf had $OneOf{<green>,<blue>,<dark>} eyes and $OneOf{<long>,<short>} hair.

The elf had dark eyes and short hair.

Whenever you use the  $OneOf{} command, make sure that the grammar is correct for all possible options and pay attention to
extra spaces, commas or dots. It is – as always – a good idea to check the results several times by pressing F4-preview.

 

Example 3:

SCRIPT

PREVIEW-RESULT

Number between 2 and 9: $Random{2,9}

Number between 90 and 110: $Random{100}

Number between 2 and 9: 7

Number between 90 and 110: 101

The $Random{} command returns a random integer-number of the given interval. If only one parameter is given, it will return a

a random integer number of the interval [0.9x , 1.1x] (+/- 10%).

Optionally, a number variable can be given as third parameter. In this case, the value is additionally stored in the variable for
further use. The next examples shows a typical use of the $Random{} command:

Example 4:

SCRIPT

PREVIEW-RESULT

The dice on the table show $Random{1,6} & $Random{1,6} eyes.

$NewVar{coins,integer,1}Next to it are $Random{20,30,coins} on the table.

"Give me the $Var{coins} bucks now, they are mine!" shouts a fat halfling.

The dice on the table show 4 & 5 eyes.

Next to it are 21 on the table.

"Give me the 21 bucks now, they are mine!" shouts a fat halfling.

 

The $Direct{} command is a hybrid of the $OneOf{} and the  $Random{} command. Depending on a given chance (in %) its
text is either shown or ignored. The text itself may contain random numbers of a given range, and optionally, the result could be
stored in a variable. Most often, the $Direct{} command is used in the pick-pocket list to list items which might, or might not be
in the inventory, as shown by the following example:

Example 5:

SCRIPT

PREVIEW-RESULT

$Direct{<There is a holy sword.>,30,1,1}

$Direct{<There are %i gems.>,80,5,10}

$NewVar{attribut,string,1}

There is a bag$Direct{< with a hole>,20,1,1,attribut}!

The bag$Var{attribut} contains nothing!

$NewVar{dice,string,1}

Five dice show the following numbers:  $Direct{<%i, %i, %i, %i, %i!>,100,1,6,dice}

The man shouts: "As I said, look! The numbers are $Var{dice}"

There are 6 gems.

There is a bag with a hole!

The bag with a hole contains nothing!

Five dice show the following numbers:  6, 3, 5, 6, 1!

The man shouts: "As I said, look! The numbers are 6, 3, 5, 6, 1!"

 

From the example you may notice that you can make the chance of the $Direct{} command 100%, which will make it appear all
the time. You can use any number of %i in the output-string, and all will be replaced by an independently chosen integer random
number of the given interval.

 

The $CaseOf{} command is a variant of the $If{} command (see tutorial 3) which allows branching depending on the value of a
variable, as shown in the following example:          

Example 6:

SCRIPT

PREVIEW-RESULT

$NewVar{d1,integer,1,$Sum{$Random{1,6},$Random{1,6}}}

A girl throws two dice. Together they show $Var{d1} spots.

$CaseOf{d1,2,<"Devil eyes"1>,3,<"3 Pigs">,12,<"Full house">,else,<"How boring">}, she says.

A girl throws two dice. Together they show 8 spots.

"How boring", she says.

or

A girl throws two dice. Together they show 2 spots.

"Devil eyes"1, she says.
or

A girl throws two dice. Together they show 3 spots.

"3 Pigs", she says.

or

A girl throws two dice. Together they show 12 spots.

"Full house ", she says.