# One-note NPCs

Publication date: 26 June 2011
Originally published 2010 in Atomic: Maximum Power Computing

Any game that contains NPCs who talk to you will also contain NPCs who say the same thing over and over. And over.

Some NPCs won't even wait for you to talk to them before they spout their sole line, like an extra who's been driven to insanity by the joy of their very first speaking part.

Often the same damn line is shared by multiple different NPCs. See, for a recent example, the countless male, female, human and Ghoul NCR troopers in New Vegas who all wish to inform you that patrolling the Mojave almost makes you wish for a nuclear winter.

There's a boring and prosaic reason for this. But first let's explore the obvious alternative:

Give NPCs a variety of things to say. Have them pick one randomly when their talk button is pressed. Simple, right?

Nope.

Actually, it's mathematically impossible for this strategy to not also, frequently, produce dialogue that repeats quite noticeably.

Let's suppose you're a game-maker and you've made the effort to give a particular NPC one hundred things they can say, and they randomly pick from that list.

When they speak again, there is therefore only a 1/100 chance they'll say the same thing they said before.

When they say their third line, though, then if the previous two lines didn't match, there's a 2/100 chance that this new one will match one of them.

If you use the standard probability-calculation dodge and calculate the probability that one or more matches won't happen, you get 1 for the first statement, 0.99 for the second, 0.98 for the third, 0.88 for the twelfth, and so on. To get the aggregate probability that a match won't happen after X choices, you multiply all X probabilities leading up to it. For the fourth statement, that's 1*0.99*0.98*0.97*0.96, a little more than 90%. But by the time you get to statement 12, the no-match probability is down to 0.44. At statement 13 it's a mere 0.39, and it gets rapidly worse from there.

(This explains the "birthday problem": You only need 23 random-birthdayed people in a room before the chance of at least two of them sharing a birthday exceeds 50%. Extending the concept, there's the cryptographic "birthday attack", based on the unintuitively high probability of matches between hashed versions of different inputs. There tend to be a lot more digits in the numbers in this application than when comparing birthdates, but the effort-reduction involved can be rather more dramatic. A birthday attack can turn a search that'd take more than ten thousand years into one that takes less than two minutes.)

So even with a hundred possible things to say, randomly picking from the list makes it more likely than not that a statement will be repeated only ten or so statements later.

This problem also affects random-play algorithms for music. A true random-play, even if the music library is large, is surprisingly likely to duplicate a recently-played track, more likely again to give you a track from the same album, and even more likely to give you a track from the same artist.

The simplest way to avoid this, and also to cure the repetitive-NPC problem, is how "shuffle"-play works: Prohibit a selection from being repeated until every other selection has already been made.

So our hundred-lined NPC randomly says something, and then randomly chooses another thing to say from the remaining 99 lines, et cetera. If two NPCs talk to each other they'll still sound as if they've suffered major brain injuries, but at least their aphasic conversational salad will have some variety.

So why do we still get so many one-note NPCs?

Well, here's that boring and prosaic reason. When you're making a game to a deadline, "NPC dialogue variety" often has about the same priority as "door of cupboard id #f3220a lacks squeaking sound". But dialogue is a lot harder to fix.

If you're making a modern voice-acted game, you'll often be neck-deep in recording extra dialogue to cover confusing events that playtesters discovered after all of the actors went home.

(Patching of this sort of problem in voice-acted games can often be quite obvious, as a character's voice shifts dramatically in tone and/or reverb in the course of one conversation, because two adjacent lines were recorded two months and 200 miles apart from each other.)

And there's not even much to be gained. Even when there's a lots of dialogue and proper scripted conversations, the player can end up just as annoyed when, inevitably, the well of unused lines runs dry. Every dialogue tree has to end somewhere, after all - and look at Poker Night at the Inventory, which is twenty minutes of funny talking trying to distract you from a seriously defective Texas-hold-'em machine.

(After this page went up, a reader pointed out to me that sports games with commentators suffer terribly from this problem. Even if there are 20 things a commentator can say when your striker misses a shot at goal or you overtake Nick Heidfeld, you're going to get very sick of all of the options pretty darn soon. You can usually turn the commentators off...)

In days of yore, of course, spoken game dialogue was rare-to-impossible, and game designers could work directly with - or be the same person as - the dialogue writers. They could fix stuff in seconds, and put huge amounts of text-only "talking" in a game that came on four floppies. But even those games have repeating dialogue in them, and many of them even have healthy populations of one-line NPCs.

(Even in a game like Animal Crossing, which has no voice acting and a huge amount of possible text-only things for NPCs to say, letters you can receive and so on, duplication starts showing up very quickly.)

The reason for one-line NPCs in games without voice acting, when it isn't just laziness or lousy writing, is that repeating dialogue is a positive feature - it informs the player that even if you're determined to Talk To Everyone, You Need Speak No Longer To This Dude. The particularly glaring example where a bunch of NPCs all say the exact same thing in their various different voices sends an even clearer, if more distracting, message.

Likewise NPCs who spout their canned line whenever you come near. Even novice players quickly realise that such an NPC is not a person, just a pseudo-animate signpost directing adventurers to the cave to the north or telling you where the marketplace is.

It's still a rather large immersion-breaker, though.

Clearly, all those lazy game-writers need do is create sentient NPCs with greater intelligence than most players.

This always seemed to work out very well in Star Trek, after all.