Regnus 5.5

The Random Text Scripting Language

The Regnus Scripting Tutorial

Part 11: Naming Numerics

Of course, in large scripts, it can quickly get confusing if you're using lots of slot numbers and need to remember which is used for what!

However, there is a way to get around this, which is to name your slots something descriptive so that you can remember quickly what they're being used for.

Now, usually, if you were to pass a non-numeric character to a slot expression, it would resolve the contents of slot 0, since non-numerics are always assumed to have a value of zero. So, for instance, the following script would work fine:

START <Storage Example>If we store the text "#>(NonNumeric):(Hello!);" like this, it will be stored in slot 0. It can then be retrieved the same way: "##[NonNumeric];"

However, there is a way to associate non-numeric expressions with specific numbers, so that these expressions will return those numbers instead when used in expressions which are read as numerics, for instance in slot expressions...

This is achieved using a new qualifier: "REFER". It is used as follows:

REFER 10:SlotName

START <Storage Example>If we store the text "#>(SlotName):(Hello!);" like this, it will be stored in the slot we defined. It can then be retrieved by number: "##[10];"

As you can see, in a "REFER" qualifier, you define first a number, and then a name for that number, separated by a colon (":") character. The "REFER" qualifier can be placed anywhere in the script, and does not necessarily have to come earlier in the script than a reference using it.

The "REFER" qualifier is not limited to slot numbers, remember; there are also other reference types which require numeric values, and this method will work just as well for those!

For example, another useful feature of the "REFER" qualifier is that you can use named numeric values in "RATIO" qualifiers to define entry weighting:

REFER 2:ExampleName

START <Example>##ExampleGroup;

GROUP ExampleGroup
ENTRY #>(ExampleName):(This text is stored in slot number 2!);
RATIO ExampleName:This entry has twice as much chance of being selected!

And there is also no reason at all that you can't give several different names to the same number, should you wish!

REFER 2:ExampleName1
REFER 2:ExampleName2

START <Example>##ExampleGroup;

GROUP ExampleGroup
ENTRY #>(ExampleName1):(This text is stored in slot number 2!);
RATIO ExampleName2:This entry has twice as much chance of being selected!