Need help with procedural generation of NPC speech in a Roguelike — when is speech unique?

For the past two weeks, I’ve been experimenting with procedurally generating NPC speech.

For context, I love Dwarf Fortress Adventure Mode, but I quickly felt that no NPC really felt unique. Thus, for a procedurally generated game I’m working on, I thought it was worth an experiment to lend NPCs a unique tone of voice, or at least unique recurring speech patterns. By using a combination of phrasal templates and individual words , I managed to build a basic model for this.

It works. That much can be said, but I’m not convinced yet. The current model takes a primary character trait and secondary trait, and constructs phrasal templates from these. Then, it fills in variables such as {attention grabber} or {exclamation} with a word chosen for that NPC. As you might imagine, this is very labor intensive.

So, my question: How much speech substitution is really needed to make an NPC feel unique, and mostly prevent repetition? Is there possibly a better way to do this? I’d love to hear your thoughts!

1 Like

It sounds like you’re already well on your way to avoiding the “procedurally generated oatmeal” problem, which is great! I think boiling it down to basic character traits (one or two per NPC) is the right way to go—my first thought would be to use register (“My good sir!” vs “Good morning!” vs “Hey there!” vs “Sup, bitch!”) and temperament (sanguine, choleric, phlegmatic, and melancholic might not be accepted in modern medicine, but if you have to put characters into a small number of boxes, it’s not a bad way to do it). Then maybe determine the phrasal template by temperament and fill in the blanks by register?

5 Likes

That’s precisely the type of blandness I’m trying to prevent. Interestingly, I had considered temperament, but for a model I’m currently exploring, I was actually thinking of using the personality types put forth by Chinese Alchemy (Water, Earth, Fire, Wood and Metal) since so many examples of these can be found in anime archetypes as well (though, this is a strictly European medieval fantasy game, the mental model just works).

I like the idea of using register as a way to fill in large phrasal sections. So if I’m understanding correctly, the phrasal template could be chosen based on the character element. Then choose forms of address and greeting based on register, and then to top it off, maybe recurring flourishes? Things like exclaiming “By the Gods!” if this was selected for the NPC, but blank otherwise.

What worries me, as is probably obvious, is that I want to prevent obvious repetition. What I had initially been looking at for this is Animal Crossing, where there are roughly 8 character archetypes, with 1 - 3 flourishes thrown in to make characters unique. This works for having 6 people in your town at any one time, but once 20 NPCs are introduced, the patterns become apparent.

My thought was that it would then be better to instead put the focus on recognition. In other words, give the NPC something the player will always recognise about that NPC. But this still means the rest needs to be properly set up. Any ideas regarding ways to vary up phrasing or make an NPC stand out are very welcome.

2 Likes

You could also do what spammers did (on this forum!) as outlined here with a few base templates that have multiple word variations. This would give two layers of change with less effort.

2 Likes

I have considered precisely this! But, there is a certain amount of consistency to be kept between NPCs, so that an NPC parses to the player as unique. What I fear this model does, is that it keeps the sentence structure the same, but you did cover this in your response. Maybe it’s worth it to offer NPCs a limited range of words in their speech pattern definition? This might work. Let me mull this over.

Actually, is there a nice library of synonyms already established that might be used for this, and could be imported into a project?

I meant having a few different structures for the same base message, as well as word variations for each structure. Each structure could have personality, and then the word variations would further define each character.

There’s no synonym library that I know of, but it should be pretty simple to find a thesaurus (like OneLook) and find words from there.

1 Like

I don’t see what’s wrong with obvious repetion if you lean into it. Maybe Animal Crossing could use more archetypes, but in principle I think players will get more out of encountering well-known characters in a variety of roles than encountering a wider but trivially different cast, particularly if not all characters are equally common. Randomization is mostly interesting when it’s applied to variables with ramifications, such as the location of NPCs or items.

I think most people would rather eat their favorite meals over and over than meals with randomized ingredients, even if they were guaranteed to be basically palatable. Why isn’t it the same with NPCs?

2 Likes

I don’t think I entirely agree. I know a couple of games with well written event systems, Stellaris comes to mind. The problem is that after reading the event chain maybe 3 times at most, the event text has lost its flavor, and I notice I begin to read past it and skip straight to the solution.

Now, Animal Crossing is a game where I do keep reading the speech bubbles. Somehow they parse as random enough to renew my interest in them, but I wonder whether this is just because there’s a limited n umber of NPCs, or whether each NPC has enough different things to say.

Now, what I do wish to prevent, as you say, is for the ingredients not up be palatable, save that’s my current quandary. How can I establish a procedural recipe book which spits out varied enough pieces of writing for it to remain interesting.

Though I have probably misread your response in part, which leads me to a different question: Say we limit the amount of possible variations, how much is enough to keep the diet from losing its flavor?

1 Like

Yeah, alright. I can see how that would work! I’ll have to look into building an experimental model based on this. That would probably be shaped a bit like the Temperament+ Register model, but with some synonym replacement.

I noticed that the game about playing at a ghost mentioned in this blog post by Emily Short does play around with that, changing wording in order to better communicate mood: Conversation as Gameplay (Talk) – Emily Short's Interactive Storytelling

However, I can’t seem to find how that model for picking synonyms works, because I don’t recognise the UI

Depending on the importance of the text, this might be exactly what the player needs. Multiple variations on The dog lounges. can be fine, but if it’s just filler text, it should be something the player ignores and not something to spend turns on (which I have done as a player with procedurally-generating text).

Example:

  • The dog rolls onto its back.
  • The dog wags its tail happily.
  • The dog chases its tail for a few brief moments.
  • The dog sits to pee.

Not so many variations that the player spends time trying to find them all (or worse, thinks that they’re important to the game), but enough to avoid complete boredom.

EDIT: You’re discussing specifically dialogue. Similar concepts still apply. Follow the Law of Conservation of Detail: things should only be as detailed as they are important.

1 Like

I’ve thought about this a lot with my sentence generators. Reading through, I think there are (at least) three kinds of variation in procedural text:

  • Content
  • Grammatical form
  • Register/tone/character

If every conversation follows the same template (or a limited range of templates), then it will be obvious (the “madlibs” effect). You can see this in the posted example, as even though there were different character tones, the format (greeting + quest + offer) was always the same. Players will skim these. One way around this is to have a wider range of conversation templates (they can still draw from the same grammar lists). For example, one fifth of the time starting with the offer and then explaining what the player would have to do.

Another aspect of what makes an NPC feel real is their embedness in the world. Dwarf Fortress takes quite a comprehensive brute force approach and fills out relationships between everyone through the world history. But even just having a few generated connections to other characters, world events etc. would help root the NPC in the setting.

A more advanced technique is to use some form of story sifting on your generated characters to foreground the most unique thing about them. In the Dwarf Fortress context, imagine if you spoke to random dwarf villager Urist McGeneric and he namechecked his more heroic cousin, or gloomily said “things haven’t been the same since a hydra took off my arm”.

2 Likes

This is a good recommendation. I have now been experimenting a bit more, and this might just work for a number of common behaviours or expressions using a text variation system. I will be taking this into account.

I had genuinely not considered varying up the order of sentences rather than the conversational template itself. This is an excellent suggeston! I will see what I can do with this, especially when it comes to narration of the randomly generated quests.

In regards to the embededness, I think we’re on the same page on not seeing a need to brute force all relations and interactions within the world using full simulation. It probably works well enough to build of a façade of deeper lore, and keep it at that.

I will be taking the suggestion of maybe picking one or two interesting quirks for a character, and reference those in speech or behaviour occasionally. That sounds like it could really make those NPCs memorable.

1 Like

Just curious, how many of these spoken NPC lines do you anticipate a player seeing in an hour of gameplay?

This is a good question, which I’m afraid I don’t have a good answer for. I suppose a player would visit a village, speak to all the NPCs there, before heading off into the wilds again, maybe speaking to an NPC two times at most.

I don’t know how long a player would be out in the wilds again though, or when they would come across another village or even city.

I must admit, I have just been trying a more longform model going by Paul’s recommendation. It does look pretty decent, and with even minor substitution, it can still achieve the goal of making the world feel alive, and giving NPCs something unique to work with.


This is just one example, there’s a couple of cases for the same type of encounter, which is drawn from the NPC archetype, combined with their Temperament (again, based on the Chinese alchemy model), so a Blacksmith feels like a Blacksmith, a Noble like a Noble, and this already does a lot for immersion.

If an NPC has a term of endearment like “Pal” or “Friend” or “Darling”, it gets thrown in the mix. Pronouns are accounted for. I just wish to build in some other unique flourish, kind of like Joey recommended. I’m thinking exclamations such as “By the Gods!” or “Hark!”, or repeating behaviours or common phrases. Any recommendations here which would make characters very memorable?

@Randozart
I asked because if enough time goes by, perhaps repetition isn’t as bad as one might think. That said, I love the idea of NPC’s delivering a bit of nuance. This is a good thing.

I haven’t quite digested everything that’s been said here, but I would say randomness excels when “the template” cannot be discerned. I like @Joey’s suggestion of random templates with “mad lib” words and phrases. There is also an opportunity for nesting sub-templates to build the whole dialog output. You could go very hardcore on this mechanic. :wink:

Personally, I’m not a huge fan of text for flavours’ sake. I like purpose; so if there was a chance of an NPC mentioning something that I could act on, that would blow my mind. It could be mentioning another NPC to seek out. It could be a rumour of a potential quest. It could be a chance to engage more with the current NPC, like…

“I noticed your bracer is damaged. For a few gold, I could fix that.” And it’s like you kind of won the lottery and you get a better piece of armour and it’s very rare and can only be done once to each piece. Knowing I could be rewarded for just talking to NPCs would encourage me to do so. If it connects with the world and feels organic… that would be the bee’s knees! :slight_smile:

Food for thought.

2 Likes

I absolutely adore this idea. I’m not sure to what extent I can implement it in this game, but I reckon it could actually be really fun to play around with. The random generator for Quests is fully functional, so I could play around with simply not displaying quest markers so you would have to find out whether someone has a task for you or not by talking to them.

Other than that, just random rewards for talking to NPCs would also be lovely (again, I am reminded of Animal Crossing, where the animals will sometimes hand you gifts if you talk to them). I am not sure whether this would be in scope, but I love the idea a lot.

What I’m currently trying to do, going by your remark about how often you really speak to an NPC, is to maintain decently curated narrative when speaking to an NPC, which is chosen based on Archetype, First Meeting or not, Task/Quest available, Temperament and some randomisation if multiple sections are available (especially important for archetypes which occur often, like a generic villager).

To give an example of this, here are three sections (split by an /O) for a Villager with an Earth Temperament on your First Meeting where they Have a Quest

If the goal is to make NPCs feel like they aren’t repeating themselves, this might do the job well enough, as randomising individual sections escape notice quickly. This should randomise things enough to keep them novel for a decent amount of time.

I am missing something though for this model to really shine, and I find I’m not necessarily lacking for ideas, but definitely implementation. Like, if I want to give an NPC a unique behavioural quirk, how could I gracefully include that in this text? Or, would that even be worth it in this specific case? What words could I replace on a consistent basis to break from the template in a noticeable way?

I could actually take a leaf out of my own quest system, and construct narrative doing something similiar, but I feel that would be going way overboard.

Actually, I could probably include a number of “rumor” sections on subsequent meetings, where the NPC comments on goings on. This wouldn’t have to be limited to Archetypes alone, and could instead just tie in with Temperament. The trick being, of course, that these are sections written in such a way that the subject changes each time, and that is what would keep those novel.

1 Like

Another way to add nuance is for NPCs to remark or act differently based on your character’s reputation and perhaps specific deeds.

The text currently reads as if you are empathetic and maybe good-natured, but what if you weren’t. If there were a way to measure your character’s alignment, it might be another avenue to spice up the generated prose. I mean, the NPCs would still want your help, but how would the prose be altered if they were a bit reluctant towards your character and perhaps just desperate enough to engage?

Of course, this sounds like a massive amount of work, but maybe there is something there that’s reasonable to implement.


Also, generating prose with a bit of guidance might be a job for that-which-must-not-be-named. If you asked it to generate a hundred greetings, then a hundred ways to ask for help, a hundred ways to accept help… it might spark an idea of how to proceed further with this. You might even just be able to copy and paste its output. If there’s one thing that that-which-must-not-be-named does well is manipulating text. In fact, it just might understand how to create templates for you, if your prompt is clear and concise enough. At the very least, it might spark more ideas for you.

2 Likes

Indeed, text processing and generation is the one thing LLMs are actually really good at. But it tends to fall into the “procedurally generated oatmeal” problem unless you’re careful.

1 Like