The Regnus Scripting Tutorial
Part 2: References, Groups & Entries
The most important capability of the Regnus scripting language is the ability to substitute parts of a text with other randomly selected text. This is done using what are called "references".
Create a new script file (or overwrite your old one!) and copy the following text into it:
START <Example Label>Hello ##SecondGroup; world!
GROUP SecondGroup
ENTRY cool
ENTRY groovy
ENTRY cruel
ENTRY brave new
ENTRY confusing
ENTRY Disney
If you open this new script with your parser, you will be given a single choice of label ("Example Label"), which will produce for you the words "Hello" and "world!", but with a random word or phrase inserted in between.
As you can see when you play with this script, the random part of the output is selected from the "entries" listed in the second block of text in the script.
These blocks of text are called "groups", and are very important to how Regnus operates. A group consists of a group name (identified with the "GROUP" qualifier), and any number of "entries", each of which is defined using the qualifier "ENTRY".
Before continuing, it would probably be best to try playing with this script a little until you are comfortable with how it works. Try adding some more entries in the second group and see what results you can make!
Note: while it's common practice to write qualifiers in capitals, Regnus is not at all case-sensitive; it is just done to make the code look tidier!
When you want to include an entry from a particular group, you use what is called a "reference"; this is what we call the little snippet of text in the script that starts with a hash character ("#") and ends with a semicolon (";").
In between these two characters lie two important parts:
- A "reference type character" (or "RTC");
- One or more "expressions".
The RTC in this case is the second hash character, but there are many other options available which we will look at later.
For now, all you need to know is that the bit of text in between the RTC and the semicolon that marks the end of the reference is called an "expression", and that when this expression is the name of a group in the script, the resulting text will be a randomly selected entry taken from that group.
Anyway, to take this concept further, create the following script:
START <Example Label>Today is ##Weekday;, so I will ##Action;!
GROUP Action
ENTRY go out and play
ENTRY stay indoors
ENTRY play with my friends
ENTRY play by myself
ENTRY go to sleep
GROUP WeekDay
ENTRY Monday
ENTRY Tuesday
ENTRY Wednesday
ENTRY Thursday
ENTRY Friday
ENTRY Saturday
ENTRY Sunday
As you can see from this script, entries can contain as many references as you want. But on top of this, entries can also contain further references...
START <Example Label>Today is ##Weekday;, so I will ##Action;!
GROUP Action
ENTRY go out and ##Action2;
ENTRY ##Action2; with my friends
GROUP WeekDay
ENTRY Monday
ENTRY Tuesday
ENTRY Wednesday
ENTRY Thursday
ENTRY Friday
ENTRY Saturday
ENTRY Sunday
GROUP Action2
ENTRY dance
ENTRY play
ENTRY sing
ENTRY fight
...And of course, each further entry can be filled with further references, creating as complex a chain of random selections as you want!
Another useful thing to know about entries within groups is that you can add a label to any entry if you would like to add the option to start parsing from that location! For example:
START <Random Selection!>##StartPoints;
GROUP StartPoints
ENTRY <Example One>Today is sunny, so I will ##Action;!
ENTRY <Example Two>I would like to ##Action; today!
GROUP Action
ENTRY go out and play
ENTRY stay indoors
ENTRY play with my friends
ENTRY play by myself
ENTRY go to sleep
If you run this script in your parser, you will see that you can choose to start parsing from any of the labelled entries. In fact, so long as a script has at least one labelled entry, there is no reason to include a "START" qualifier at all! The following script will work just as well:
GROUP StartPoints
ENTRY <Example One>Today is sunny, so I will ##Action;!
ENTRY <Example Two>I would like to ##Action; today!
GROUP Action
ENTRY go out and play
ENTRY stay indoors
ENTRY play with my friends
ENTRY play by myself
ENTRY go to sleep
So, go ahead and play around with your script and see what you can do with what you already know – and then come back for the next chapter once you're comfortable with those concepts!
Note: When naming groups, you can use any letter or number character, and also the hyphen ("-"), full-stop ("."), underscore ("_"), exclamation-mark ("!") and question-mark ("?") characters.