When simple text generation is simply not enough: Part 3
Now that we know how to create a grammar context and how to reference different GrammarAttr objects in our parameter list, as shown in last week’s simple example sentences, let’s take a look at more complex scenarios.
This is a reasonably complex sentence, I think, that can occur anywhere in any role-playing game. Without a proper dynamic text system, it is hard to fully take control of it, and it would require a lot of a special coding to catch all possible cases, however. For us, its challenges are solved in a breeze.
Let’s look at the structure of this sentence first and break it down, like this.
A lot going on here, wouldn’t you say? Using my Grammar engine, however, this entire structure is easily represented in this way.
Once again you will notice the elegance of the implementation because Grammar always makes sure that the source sentence remains readable and understandable. This will be especially important once you try to localize your text. In those instances, cryptic implementations will instantly cause trouble and create translation errors that are time-consuming to catch and handle.
To further illustrate the power of the Grammar module, here are more possible, dynamically created output sentences stemming from that one template. As you will see, none of them feels like a cheap cop-out that attempts to circumvent grammar issues the way all-too many games do.
Assuming that all nine ring wraiths descend upon the poor hobbit in our previous example, we would get this result.
Notice, among other things, how the [his-her] and [he-she] tags are correctly expanded to their and them in this case because there are now multiple monsters and swords in play. And all without a single line of extra coding!
Alternatively, we could generate this output…
or this one, referring to his sword by name, instead of the generic description.
Let me stress it again, that all these sentences have been created from the same source template that you see above. The Grammar logic is doing all the hard work for you to match articles, pronouns, names and grammar cases in order to form a grammatically correct sentence. It’s almost like a little bit of magic. 🙂
To allow for this kind of flexibility, the Grammar module needs a certain vocabulary; tags that it can interpret and adjust, respectively. This vocabulary contains the most commonly used terms, such as pronouns, verb forms, article forms and others, and, if need be, it can be easily expanded to accommodate even the most complex situations. The system I’ve designed gives me the freedom to shuffle things around efficiently, just the way I need it.
This is, perhaps, best evident when you look at other languages, most of which are considerably more complex than English. Here, for example, is what the above example could look like when it is being translated into German—a language with highly complex grammar rules.
Despite the language’s own complexity, you can see that, outwardly, the tagging does not appear much different from the English version—except for the fact that, like the sentence, they are in German, too. The complexity is hidden under the hood, as these tags are being interpreted. The fact that these tags are actually German, takes any guesswork or awkwardness out of translating the text. The result will be translations with fewer errors and misinterpretations.
The source sentence above, when interpreted by Grammar, would result in an output somewhere down these lines…
Nice, isn’t it? Because of its complexity, the German implementation contains a much larger vocabulary to interpret, but for the writer, this is irrelevant, because the sentences are tagged in their native, natural language.
And the same approach works for Spanish or any other language. The module provides the most commonly used native Spanish tags that will allow writers and translators to easily create sentences that take the respective grammar into consideration.
If you are interested in the Grammar module, it is now available in the Unity Asset Store. It currently supports English, German and Spanish languages. It is easily expandable, both with additional tags and to support any other language. In fact, I could easily write language modules for Elvish or Klingon, if there were any demand for such a thing.
And since it’s all fully abstracted and encapsulated, it’s usage could not be simpler. And all it takes to switch to a different language is a single API call. The rest would fall into place automatically, in real time, without processing or additional data overhead.
And just like that, we solved a problem—and elegantly so, I would say—that has limited game developers for three decades. Don’t be the one to use banal sentence structures in your narratives. Grab a copy of the Grammar script package and leave your sordid, nondescript language past behind!