Mechanics: Modular Writing – Part II – A Practical Lesson

Alright, now that we know a bit more about what modular writing is, let’s try to do something in practice. In this case, I’ll use the game’s engine (haha, not like I have any ulterior motives by doing this, hint hint) as a way of verifying what we’re doing in practice. Meaning that this will be more of a practical lesson in modular writing rather than an article.

So, let’s start with getting things ready. We’ll need to make some changes in the game’s configuration to enter, let’s call it, “creator mode”. In the main menu, go to Options, then Configure Game, and scroll down to the bottom of the page. There are two options there you need to set. Developer Mode needs to be set to Enabled, and Cache Mode needs to be set to Disabled. Note that the second of these two options has a negative impact on game performance; if you want to just play around with what’s in the game, it might be better to revert those options. After accepting these changes, you will note that new entries are available in Options. Press the Run Console button, where we’ll be testing our modular writing.

mw001

1) The console

Here, we’re looking at a way to tell the game engine to run code and observe the results. Don’t worry; we won’t be doing programming; what we’re doing here is classified as a formal grammar.

Let’s try something straightforward to begin with: type or paste (copy and then press the Paste button) this line into the input, then press Submit:

p: Hello, Reader!

mw002mw003mw004

The command stands for print, and it will print anything after the colon while resolving so-called non-terminal symbols. In the previous article, we discussed how a modular writing system has to have some way of inserting said writing into the game. For this system, these non-terminals are one of the ways of telling the engine to pull and insert something from a file. We’ll be discussing the details of this shortly, but for the moment, let’s start with a demonstration.

p: [^data\phrase\hello$all$no-resolve,hello,casual,friendly,dont-finalize], Reader!

This line tells the system to use the file data\phrase\hello as a source (this file is inside of data.zip; you don’t need to take it out of there, nor do you need to put your own files inside of data.zip), and we want a line from it that possesses all of the following tags: no-resolve, hello, casual, friendly and dont-finalize. The exact way this works is out of the scope of this lesson, as this is a non-trivial source, but it does match with what we’ll be doing; we’ll just be a bit more direct about it. As a concept, however, calling back to the previous article, I did mention we will need to tag our content; this is one side of what I meant. We’ll look at the other side when making our own source file.

B.t.w. we can generate a few such lines all at once like this:

loopn 10: p: [^data\phrase\hello$all$no-resolve,hello,casual,friendly,dont-finalize], Reader!<br><br>

mw005

This means repeating the following command 10 times, and the <br> at the end is the HTML way of saying “go to the next line”.

2) A source file

Let’s go to the folder where we have our engine executable, that is to say, where you have the Esoteric.exe file you use to run the game. I’m going to guess that you have your file extensions hidden, and as such, the file appears as just Esoteric. That’s fine; it doesn’t bother us in any way. We want to create a text file here called apple.txt, but again, with hidden file extensions, this will just be a text file called apple.

Now, open that file in Notepad. I personally use Notepad++, but the standard one provided with Windows is fine.

Let’s add two lines to it:

eat;You eat the apple.
crush;You crush the apple in your fist!

mw006

We now have two lines here, examples of modular writing on the level of sentences. Each of the sentences is given one tag. For the first, that’s eat; for the second, that’s crush. The semicolon then divides the tags from the content. It’s best to not have any spaces before or after the semicolon, but it is possible to put one after it. We just don’t.

Now that we have some content in our source (pssst, remember to save the file, or else the engine can’t read it), we can call to it, much in the same way we did with the hello file before.

loopn 10: p: [apple.txt$all$eat]<br><br>

We’ll be using this line for testing a lot! So when I say we want to run our test, I mean running this line in the console.

As we run this test, we see that the line tagged with eat is pulled from our source and inserted here. But it’s rather pointless, considering there’s just one option. So, let’s diversify our writing a little bit, let’s change the content of the file to this:

eat;You eat the apple.
eat;You consume the apple.
eat;You devour the apple.
eat;The apple disappears down your applehole.
crush;You crush the apple in your fist!

And let’s rerun the test. Now, the output changes to pull one of those four options randomly, or so it seems. It’s not that simple, but for the moment, we don’t need to worry about anything more.

3) Building a paragraph

Now that we have a working source file let’s do something bigger. Let’s construct a whole paragraph describing taking a bite of the apple. For the moment, the structure will be simple: we pick up the apple, bite it, and put it back down, three sentences forming a short paragraph of writing together. Oh, also, we’ll be removing the crush line. We don’t need it, and removing it means I need to copy less code here:

eat;[apple.txt$all$pick-up]
pick-up;There is an appealing-looking, crimson apple on the table; you pick it up. [apple.txt$all$bite]
bite;You raise the apple up to your lips and sink your teeth into the slightly waxy surface, the juicy flesh underneath spraying flavourful liquids into your mouth. [apple.txt$all$put-down]
put-down;You return the teeth-marked apple to the table.

I would highly suggest that you try to write your own sentences as an exercise.

The approach we’re using here is called a regular construction. That means that once we run our entry point (tagged with eat), each sentence will insert the following one. This could also be done differently, like so:

eat;[apple.txt$all$pick-up] [apple.txt$all$bite] [apple.txt$all$put-down]
pick-up;There is an appealing-looking, crimson apple on the table; you pick it up.
bite;You raise the apple up to your lips and sink your teeth into the slightly waxy surface, the juicy flesh underneath spraying flavourful liquids into your mouth.
put-down;You return the teeth-marked apple to the table.

Currently, there is no difference in the content generated by both approaches. However, we’ll see where it matters as we go further into this tutorial. Overall, it is my firm opinion that a regular construction is the superior way of building paragraphs out of sentences; as such, we’ll just continue on with the first version. What we need is a bit of variety, so let’s make three variant sentences per each tag:

eat;[apple.txt$all$pick-up]
pick-up;There is an appealing-looking, crimson apple on the table; you pick it up. [apple.txt$all$bite]
pick-up;A scrumptious red apple sits on the table nearby; you snatch it daftly. [apple.txt$all$bite]
pick-up;Upon the nearby table sits an appetising red apple. You reach out and pick it up. [apple.txt$all$bite]
bite;You raise the apple up to your lips and sink your teeth into the slightly waxy surface, the juicy flesh underneath spraying flavourful liquids into your mouth. [apple.txt$all$put-down]
bite;As your teeth dig into the fruit’s waxy skin and juicy flesh, the rich, tart flavour coats your tongue. [apple.txt$all$put-down]
bite;Your lips close around the fruit as your teeth tear out a chunk of the flesh, cutting into the skin. The apple sprays its juices into your mouth, filling it with flavour. [apple.txt$all$put-down]
put-down;You return the teeth-marked apple to the table.
put-down;The apple returns to its perch on the table, now with a chunk taken out of the side.
put-down;Having a nice bit, you put the apple back on the table.

Do note that while these are “sentences” in the modular writing sense, in terms of literal writing, we can divide them up into smaller sentences if we want to.

Now, if we run our test, we get a variety of different outputs. There are 27 unique combinations for these 9 lines. That might not be enough for an often repeating segment of text, but it serves for our presentation here.

This is a modular paragraph at its most basic, so let’s still work on it a little bit more.

4) Adding subrandomisations

One thing we can do is add some subrandomisations. What do I mean by that? Well, let’s just do this for the lines tagged as pick-up. We can identify that a few synonymous constructions are being used there. The apple can be either red or crimson; it can be described as scrumptious, appealing-looking, or appetising. And it can be either picked up or snatched from the table. Let’s make it so that all lines can use those alternatives. To do so, I’ll employ a simple in-line non-terminal.

p: [?First alternative|Second alternative|Third alternative]

If you run this line in the console, you will note that it always resolves to one of the texts divided up with the bar symbols (|). We can use this in our texts (note that I’m only showing the altered lines here):

pick-up;There is [?an appealing-looking|a scrumptious|an appetising], [?crimson|red] apple on the table; you [?pick it up|snatch it]. [apple.txt$all$bite]
pick-up;[?An appealing-looking|A scrumptious|An appetising] [?crimson|red] apple sits on the table nearby; you [?pick it up|snatch it] daftly. [apple.txt$all$bite]
pick-up;Upon the nearby table sits [?an appealing-looking|a scrumptious|an appetising] [?crimson|red] apple. You reach out and [?pick it up|snatch it]. [apple.txt$all$bite]

If you rerun the test, you’ll note the non-terminals resolve in such a way that our synonyms are used by all lines.

5) You… you… you

One rather unfortunate effect of the English syntax is how often it’s possible to repeatedly start a sentence with a pronoun. Generally, this leads to rather monotonous and uninteresting writing, though sometimes it is quite unavoidable. Still, we can do something about it here.

For our bite and put-down lines, let’s mark the ones that start with “You” or “Your” with an additional tag ~previous-you. This tag signifies that the previous sentence started with you; the tilde indicates that we don’t want this tag. Next, when we call the following sentence in our pick-up and bite lines, we’ll pass previous-you to our non-terminal if that line starts with “You”:

eat;[apple.txt$all$pick-up]
pick-up;There is [?an appealing-looking|a scrumptious|an appetising], [?crimson|red] apple on the table; you [?pick it up|snatch it]. [apple.txt$all$bite]
pick-up;[?An appealing-looking|A scrumptious|An appetising] [?crimson|red] apple sits on the table nearby; you [?pick it up|snatch it] daftly. [apple.txt$all$bite]
pick-up;Upon the nearby table sits [?an appealing-looking|a scrumptious|an appetising] [?crimson|red] apple. You reach out and [?pick it up|snatch it]. [apple.txt$all$bite,previous-you]
bite,~previous-you;You raise the apple up to your lips and sink your teeth into the slightly waxy surface, the juicy flesh underneath spraying flavourful liquids into your mouth. [apple.txt$all$put-down, previous-you]
bite;As your teeth dig into the fruit’s waxy skin and juicy flesh, the rich, tart flavour coats your tongue. [apple.txt$all$put-down]
bite,~previous-you;Your lips close around the fruit as your teeth tear out a chunk of the flesh, cutting into the skin. The apple sprays its juices into your mouth, filling it with flavour. [apple.txt$all$put-down,previous-you]
put-down,~previous-you;You return the teeth-marked apple to the table.
put-down;The apple returns to its perch on the table, now with a chunk taken out of the side.
put-down;Having a nice bit, you put the apple back on the table.

mw007

While this reduces the number of possible generations, it does make the remaining ones a bit more elegant. Modular writing often requires a degree of finagling the balance between the breadth of what can be generated and the quality of the generation.

Interestingly, if you did what I asked initially and wrote your own content, we could now combine our files to vastly increase the number of outcomes that can possibly be generated.

We can still improve this, but I’d like to leave that to the third part of this tutorial. This one is lengthy already. We can then talk a little bit about alternative constructions and modular writing that takes different paths.

Now for your “homework”, why not pick a writing prompt (like, let’s say, “sniff a rose”) and write your own modular description of the action?

Leave a comment