Skip to content
A simple branching dialogue and ask/tell engine for conversations in RPG-style games
Branch: master
Clone or download
scottbw Merge pull request #1 from cjke/feature/requirejs
Changed export line to be compatiable with requirejs via a shim
Latest commit 717a7e9 Feb 17, 2015
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples initial commit Nov 23, 2013
script added graffle script Nov 28, 2013
LICENSE Initial commit Nov 23, 2013 Update Dec 3, 2013
logo.png added a logo Dec 3, 2013
package.json guard against actors with no dialogue Nov 23, 2013



A simple branching dialogue and ask/tell engine for conversations in RPG-style games

Installing and using

Use NPM to install:

npm install dialoguejs

You can then create a dialogue object, holding all dialogue states, using:

var mydialogue = require('dialoguejs');

Loading dialogue from a text file

To load dialogue for a character, call

dialogue.load(actor, file)

For example:

dialogue.load("gnu", "gnu.txt");

... loads dialogue for "gnu" from "gnu.txt".

Interacting using ask/tell

The format of the request is

dialogue.interact(actor, player, topic)

For example,

dialogue.interact("gnu", "player", "banana")

... returns:

{ text: "I hate bananas" }

Interacting using branches

Branching dialogue follows a similar structure. An interaction request uses:

dialogue.interact(actor, player, [response_id])

For example:

dialogue.interact("gnu", "player")

... returns

{text: "Hi! Welcome to OSSland! Is this your first visit?",
 responses: [
    {id: 1, text: "Yes, I just arrived"}, 
    {id: 2, text: "No, I've been here before"}

... and then if the player selects a response, we can call:

dialogue.interact("gnu", "player", 2)

... which would return:

{text: "Hey, welcome back"}

Note that dialogue state is maintained for player-actor combinations, so if multiple players converse with a NPC, they can each have a different state within the conversation with that NPC.

Creating a script

Dialogue scripts are simple text files. Each line of dialogue is on a separate line, and starts with an identifier. This must be a number for use in a branching dialogue, or can be a word if using ask/tell. (Both types can be combined in one dialogue file)

After the identifier comes the text to be returned, followed by either a set of response options, or the next line to follow.

For choices, put identifiers in square brackets, e.g.

1 Where is the Grue? [3,7]

... indicates that, along with this text, the player should be presented with lines 3 and 7 as possible responses.

For moving the dialogue on, use a dash-and-angle-bracket arrow (->) followed the line number, e.g.

3 In the dark -> 4
4 Yes, I suppose it is -> 5
5 Hello again, nice to see you

... indicates that, if the player responds "In the dark" (3), that the next line spoken by the actor will be "Yes, suppose it is" (4). The dialogue state will then move onto number 5.

You can’t perform that action at this time.