Event Tutorial - 02 - The Data


Continuing with the event, we'll now focus on this node. It's a good place to prepare any variables we might need later. No matter if we're using the scripting or the grammar language, it uses the same memory, and the scripting language has a lot more power over it. In essence, the scripting can create, write and read variables, while the grammar can only read them. In practice, because both languages inter-operate, this isn't very important, but it does mean we need to use scripting to declare the variables we want.


1) Declaring some variables

Let's start with declaring a possible intent for the NPC, this will control a lot of the different interactions with the event, so it's a good candidate for being decided first. We can then use it as a basis to generate the rest.


The expression in the first line of the node will assign it based on decorating the grammatical statement to follow. Decorating a text just means trying to resolve all non-terminals still there. In this case, we have one; it's perhaps the simplest of all non-terminals, it will resolve as one of the random text within the square brackets. So this lets us set up four different intents (for the moment) and give them different probabilities by repeating them. You can think of it as making a custom die with various texts on the faces and rolling it. It has no other features.

I've also went ahead with a few other things, a colour for the NPC's text and two slots for an attribute describing the NPC. But for the moment let's focus on the colour, I want the colour to be somewhat associated with the intent. For that, let's look at a few things, firstly, the file that categorises the colours with various attributes:


And the colours they map to:


I think the kind of association I want to make might look like this:

  • accident: any,
  • charming: light and warm,
  • smile: light or warm,
  • lewd: dark or cold,

To do this, though, I'll need another file, so let's start one up. For most events, this file will be called the same as the state file (the file we generate from TreeNote, eventually), and is essentially a set of production rules we'll filter in different ways:


Ok, so let's discuss what this does for a moment. The purple part on the left of the semicolon is the context associated with the given production rule. The part on the right of the semicolon is the result of the production rule. In this case, it also contains a non-terminal. This construction refers to a file containing production rules (just like this one), specifically to the one containing generic colours for NPCs. The structure of this call is:

  • source, a file with production rules;
  • selector type, the any selector here requires for the context to contain any one of these comma-separated tags;
  • the set of tags.

We can then use it in the TreeNote file, but this time we'll use an all selector, so it chooses a production rule that has both colour and the generated intent in its context:


2) Random generation using production rules

Now we need just to generate the attributes. I'd like to have two of them, and I want them to make sense. So we want to take into account the intent, as people with different intents will tend to look differently, and we don't want the two attributes to contradict each other. We don't want a brown-haired blonde or an obese gaunt man. The critical thing to remember right now is that these are just keywords we'll use later to call the descriptions, we'll process and further diversify them later:



The ~tag1 denotes that this tag must not be within the given tags. In comparison, the +tag1+tag2 notation represents the complementary operation to the current selector. Thus within an all selector, it will require any of those tags, and within an any selector it will need all of them. In essence, these features allow the construction of propositional normal form expressions (disjunctive normal form / DNF, conjunctive normal form / CNF, look it up if you want to know more).

So to use an example: attrib-gen,~dishevelled,~plain,+accident+charming, this requires that:

  • the context contains the attrib-gen tag;
  • does not contain dishevelled;
  • does not contain plain;
  • includes either accident or charming.

For the moment, we'll end here; this tutorial is long and probably difficult as is. Next instalment, we use these features to start generating some text.

Get Esoteric ♥ Esoterica

Leave a comment

Log in with itch.io to leave a comment.