Gamasutra: The Art & Business of Making Gamesspacer
View All     RSS
March 30, 2017
arrowPress Releases

If you enjoy reading this site, you might also want to check out these UBM Tech sites:

Creating Better NPCs
by Paul Tero on 03/18/13 07:06:00 am   Featured Blogs

The following blog post, unless otherwise noted, was written by a member of Gamasutra’s community.
The thoughts and opinions expressed are those of the writer and not Gamasutra or its parent company.

Do many gamers remember Zelda II: Adventure of Link? It was an excellent fantasy game for the first Nintendo Entertainment System which occupied quite a lot of my evenings in 1989. The Non Player Characters were very basic though - typically a lone villager who hints which direction to head for the next dungeon. The villager kept on repeating the same hint long after I'd moved on. Nintendo's NPCs are not much better in the latest Zelda instalment Skyward Sword in 2011, despite over 20 years of computer and game development in between.

Adventure of Link screenshot Skyward Sword screenshot
Nintendo's Zelda series from 1987 to 2011, a huge leap in graphics but not dialogue. 

There are now many computer and online games where NPCs are better than this, where the NPCs do follow more complex branching dialogue trees. However the player's path through the tree is often by multiple-choice (as in Skyward Sword above) or keyword recognition. There's a lot of room for improvement, particularly in allowing the player to type whatever they want and engage in a conversation with an NPC, rather than repeatedly receiving the same limited set of preset statements. NPC chatting was one of the key areas of future game development identified during a conference review posted on Gamasutra a few months ago.

Software available
Chat Mapper screeshotThere are a few different approaches to making NPCs to include in games. There are visual dialogue engines like Chat Mapper (screenshot on right) which allow you to describe your NPCs and map out branching dialogues. There is a more ad-hoc approach, using bespoke XML files to plan dialogue so it integrates well with the rest of the game. Interactive fiction is another related field. And there are chatbots - which specifically focus on engaging dialogue. They encourage free text input and can produce a variety of output. This blog post is about the conversational side of NPCs and so only discusses chatbots.
Skill set
The required skill set to use any of these approaches is somewhere between a developer and a writer. It can be a very fun and creative process. However it can also take a long time. Developers may find the writing aspect tedious and writers may find it the logic of it overwhelming. It is maybe better approached by a team of people working together.

What to look for
The first difficulty in creating NPCs is knowing what to look for in Google. You might try searching for "npc creators" or something similar. But that tends to bring up websites for generating random NPCs for role playing games like Dungeon & Dragons (hit points, weapon types, things like that).

Instead try searching for "chatbot creator". The term "chatbot" has different scope from "NPC". At one end, it covers virtual assistants for websites and smartphones - from IKEA's Anna to Apple's Siri. At the other is the more academic challenge of the Turing Test to see whether an artificial intelligence is capable of imitating a human. But since it is the chatting ability of NPCs that seems most lacking in current games, chatbots are a good place to start when thinking about how to spice up NPCs. The term "bot" is also used for "chatbots" but if you search for "bot makers" you get everything from 3D printers to web crawlers.
Chatbot software
At the end of this article is a selection of chatbot makers that I have come across, including one that I have helped to develop. They all rely on the creation of a file of some sort (text, XML or spreadsheet) which is then processed by the software and turned into a bot which you can chat too. The format used usually directly associates a player's input (such as "which way to the dungeon?") with the chatbot's output ("second cave on the right").
The problem is that there may be millions of unique ways of asking "which path should I take to the next dungeon?" and hundreds of ways of answering "enter the second cavern on your right". The goal of the developer/writer is cover as many of these as possible in a reasonable amount of time. The easiest approach is to look for the keyword "dungeon" in the user input and then always give the same reply. But that's pretty much what NPCs do now and could be programmed quite simply without any third party software.

One of the main challenges therefore is to build a chatbot which can recognise thousands or millions of inputs without you having to type them all, and which can give many variations of output. That's what the software below provides, with varying degrees of success.

Another challenge is how they handle branching scripts - where one question leads to another. None of the chatbots below have a visual data entry format like the dialogue engine above - partly because it would limit their flexibility, and partly because it would take a long time to program. Instead they have systems for setting and getting variables and giving different outputs depending on them.
Skyfall game created using CleverscriptCleverscript is made by the company behind the very popular Cleverbot. It uses a spreadsheet format and has powerful tools for organising language and maintaining variables. Spreadsheets are uploaded at the Cleverscript website and turned into bots which you can test. The lines of the spreadsheet look roughly like this:
input hello hello / hi / hi there
output      hello      Hello!

To use the bots in your own website or app, you have to pay for access to a web service, or to request libraries for inclusion in smartphone projects. One of the big advantages of Cleverscript is that it includes a mini-Cleverbot engine, which means you don't have to script all conversation. It will be able to small-talk out of the box. On the right is a screenshot from a game which used Cleverscript and promoted the film Skyfall.
AIML stands for Articifial Intelligence Markup Language. It is an XML format used for creating a chatbot. The format looks like this:
  My name is John.

The most famous AIML chatbot is ALICE, the Artificial Linguistic Internet Computer Entity. When you create your own AIML bot, you can include ALICE's AIML as well as libraries contributed by other AIML users, including in several European languages. This reduces the data entry burden. Having created your XML file, you need some means of running it. The easiest method appears to be as a free web service provided by Pandora Bots. There are also several interpreters available in different programming languages including C++ and Java so you can run it yourself.
Tom Loves Angela screenshotChatScript is a free open-source C++ library. You can compile it for whatever platform you need. Outfit 7 used ChatScript to power their popular Tom Loves Angela app (screenshot on right) for Google Android and iOS. Bots are created using a text file which contains lists of expected user inputs and corresponding bot outputs. They look like this:
u: (what are you) ^keep() ^repeat() I am a bot.

The format includes methods for reusing text and remembering user preferences. The text file is run though the software to produce a bot you can chat to. The software can be compiled into your own game and run directly on a smartphone or your web server.

I am biased because I helped to develop Cleverscript. I think it is more flexible and powerful than the others, including an advanced variable system and an intuitive way of organising language. There is less data entry needed, and it handles branching scripts fairly well, though a visual data entry format would enhance it. Among the free ones, I favour the more compact format of ChatScript, even if it is more technical. I personally also prefer that the interpreter is written by the same person/people who came up with the input format. It means that changes and additions to the format develop alongside the software itself.
There may also be other software packages and approaches out there too, but I've focused only on popular chatbot creators. And to be fair to Nintendo - allowing free text input on a joystick would have been very tedious. They are still great games.

Related Jobs

Crate Entertainment
Crate Entertainment — Boston Area (or work remotely), Massachusetts, United States

Senior Programmer
Crate Entertainment
Crate Entertainment — Boston Area (or work remotely), Massachusetts, United States

Graphics / Engine Programmer
Sony PlayStation
Sony PlayStation — Bend, Oregon, United States

Sr. Animation Programmer
Improbable — San Francisco, California, United States

Software Engineer

Loading Comments

loader image