Procedural generated Text


Hello Everyone, I have a text generation framework I built in PHP that stores text in an array of possibilities an rebuilds the content when accessed so that the text is never the same twice.

It takes much longer than writing a paragraph one time, but its much much much shorter than paraphrasing the same paragraph millions of times to get every possible unique combination of words.

It was actually my own dream to create an Interactive Fiction game using this technique which sparked me to do some research before I started building the entire game engine from nothing.

Now the problem is that PHP is not compatible with the technologies that are commonly being used.

So I’m going to need to rewrite it to extend the current framework, or provide it as a module, which is the thing I am specifically looking for advice on in this thread.

So is this something anyone would be interested in having?

I can describe the basic functionality of the class below.

Class word soup:

function words: store a word list, usually a list of synonyms.
function sentences: store sentences lists, usually the same sentence used.

Inside a sentences word lists are templated into the sentences using tildes ~word_list~.

The tildes have a bunch of operators that include

  • capitalise the first letter of the word returned from the word list

@ if the words in the word list have some letters beginning with a you can dynamically switch between an apple and a banana

& a list such as : I have a, b, and c where a,b, and c appear in any order.

There are other various functions that handle building sentences into paragraphs and assigning probabilities for certain phrases to appear and the specific order they do appear.

I really believe these could entirely revolutionise all video games as now there is the possibility for NPC’s to never have stale text that reads twice the same way.

I am very keen on some feedback, so looking forward to some replies.


You can post it as a composer module. You never know what tech stack could become the next big thing, and PHP is not a niche language.


If you’re interested in current projects that use generative text, there’s a recent list here.

There are games that make use of generative text in current languages. Begspace in Twine, and Apocalypse Fuel in Inform 7 both come to mind.

Inform 7 includes tools for text variation that maintain readability of the code while allowing different kinds of random variation. So for instance:

say "[one of]Today[or]Yesterday[at random] [one of]I[or]we[or]they[then purely at random] [one of]went to[or]visited[or]robbed[as decreasingly likely outcomes] [one of]the bank[or]the cornershop[or]my mother's drawing room[sticky random]."

Tracery is a scripting tool underlying the cheap bots done quick twitter bot creation website. It allows word lists list with each randomised word (or sentence) able to be drawn from unique lists which can themselves contain randomised elements.