Create Your Own Generator Using Campaign Logger’s Engine

Campaign Logger includes a generic engine you can use to create your own generators for the app. It works by defining how the result should look and then providing tables from which to pick elements for the desired result. It’s a bit like making Mad Libs.

For example, “the result should be a name which consists of a first name followed by a last name.” So, you would provide the generator with two tables:

  1. First names
  2. Last names

This sounds almost stupidly simple, but the potential to run complex generators is right at your fingertips, so bear with me and come along for a little generator delve.

Example: Creating a Traveller Patron Encounter

In this tutorial I want to create a generator that puts together a random adventure outline loosely based on Traveller’s patron encounter concept.

Following this concept, we need to generate:

  • A patron
  • A mission
  • Requirements
  • Rewards

For this tutorial, I will focus on building a generator for the first two: a patron and a mission.

The Basics

The engine is fed with text in JSON format. JSON stands for JavaScript Object Notation, which sounds intimidating at first but really is easy to understand and use once you play with it a bit.

An “object” in JSON is a list of names and values. Consider a Person object with a first name and a last name. In JSON this might look like this:

{
   "first-name": "Jochen",
   "last-name": "Linnemann"
}
  • An object always starts with an opening curly brace “{“ (first line in the example) and always ends with a closing curly brace “}” (last line in the example).
  • The named values of an object are separated by commas “,” (end of second line in the example).
  • A named value consists of a name and a value separated by a colon “:” in the format “name: value” (second and third line of the example).
  • The name is always surrounded by double quotation marks “”” (the basic ones, not those fanciful ones which get inserted by many modern word processors to indicate direct speech).
  • In our example, all values are also surrounded by double quotes to indicate text values (there are other kinds of values JSON supports besides text, one kind being objects).

So objects are lists of named values. There are also lists of unnamed values which get called “arrays”. Arrays are like lists or tables.

Consider a list of names which might look like this in JSON:

[
   "Alexandra",
   "Charlie",
   "Pete",
   "Georgia"
]
  • An array always starts with an opening square bracket “[“ and always ends with a closing square bracket “]”.
  • The values of an array are separated by commas “,” (like named values in an object).
  • The values are surrounded by double quotation marks “”” to indicate text values (other kind of values are e.g. objects and arrays).

Getting Started

Now we know the general format conventions on which Campaign Logger’s generator engine is based, so here is the general template for a simple generator:

{
   "resultPattern": "{firstname}",
   "tables": [
   {
      "name": "firstname",
      "entries": [
      "Alexandra",
      "Charlie",
      "Pete",
      "Georgia"
      ]
   }
   ]
}
  • Every generator is an object with two named values:
    • “resultPattern” which names a text value, and
    • “tables” which names an array of table objects
  • A table object has always two named values:
    • “name” which names a text value used to reference the table, and
    • “entries” which names an array of text values

That’s the JSON part of the generator. As a convention, the engine treats text in curly braces (like “{firstname}”) within text values as table references. When the engine encounters such a reference it looks for a table with a corresponding name and selects a value from that table randomly to be inserted in place of the table reference.

Testing the First Generator

The JSON above is a fully functional generator. You can copy and paste it into the text area on the generator service home page and try it out:

Copy and paste the JSON code into the text area on the generator service home page

Copy and paste the JSON code into the text area on the generator service home page

Fleshing It Out

Having understood the general principle and seen the generator in action we can now proceed to reach the stated goal. The result pattern for the patron encounter could start out as “{patron} {mission}”. A patron will have a name and a role/occupation/class, so “{name} the {role} offers the following mission: {mission}” would be a better spelled out result pattern.

Names could consist of just a first name, a first name and a last name, a title and a first name, etc. So I will use a nested pattern here: The name table’s entries will themselves reference other tables for random results and by repeating a specific entry I am increasing the likelihood of that result:

{
   "resultPattern": "{name} the {role} offers the following mission: {mission}",
   "tables": [
   {
      "name": "name",
      "entries": [
         "{firstname}",
         "{firstname} {lastname}",
         "{firstname} {lastname}",
         "{firstname} {lastname}",
         "{firstname} from {locale}",
         "{firstname} from {locale}",
         "{title} {firstname} of {locale}",
         "{firstname} {title} {locale}"
      ]
   },
   {
         "name": "firstname",
         "entries": [
            "Alager",
            "Edred",
            "Heimwart",
            "Radulf",
            "Ascwin",
            "Hamera",
            "Linddis",
            "Walaruna"
         ]
   },
   {
      "name": "lastname",
      "entries": [
         "Dissibod",
         "Erchanold",
         "Fastburg",
         "Gerbrand",
         "Sigwald",
         "Wynflaed"
      ]
   },
   {
      "name": "locale",
   "entries": [
      "{lib:nameVillage}"
      ]
   },
   {
      "name": "title",
      "entries": [
         "Mayor",
         "Judge",
         "Sheriff",
         "Squire",
         "Knight",
         "Baron"
      ]
   },
   {
      "name": "role",
      "entries": [
         "Chief Warrior",
         "Well-Known Expert",
         "Travelling Expert",
         "Local Aristocrat",
         "Visiting Aristocrat",
         "Town's Adept",
         "Bard",
         "Cleric",
         "Druid",
         "Ranger",
         "Sorcerer",
         "Wizard"
         ]
      }
   ]
}
  • You may have noticed that I cheated in the “locale” table, I referenced a library file there which creates village names. We are currently building up a library for you and us to use in future generators. There are currently 106 files in that library and we will treat them in a future article.

Completing the Mission

Finally, we need to add a mission statement to offer to the characters. This can be become as complex as one desires. But to keep the article focused on showing how to use the generator engine, I decided to just have a main mission and relatively unconnected sub mission which gets simply tagged to the main one. The complete generator JSON will be appended to this article. Here is an example output from that generator:

an example output from that generator

Example output from that generator

Happy Generating!

Tools and References

The Campaign Logger Generator Homepage and Help Page are essential for getting new generators working the way you like.

For the technically inclined, the JSON Homepage is a good start to delve into the details of the JavaScript Object Notation.

And finally a nice editor for writing JSON is Visual Studio Code which is available for Windows, Linux, and Mac.

Appendix

Appended you will find the JSON file containing the generator created in this article. Use it under Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0: https://creativecommons.org/licenses/by-sa/4.0/).

Click Here to Leave a Comment Below 5 comments