A very basic example of using Tracery to create dialogue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create two Tracery objects | |
var tracery = require("tracery-grammar"); | |
// Create a Person class | |
function Person(id) { | |
this.id = id; | |
this.say = function(words) { | |
console.log(id + ": " + words); | |
} | |
} | |
// Create two simple people objects | |
var personA = new Person("A"); | |
var personB = new Person("B"); | |
var symbols = { | |
"like": ["benches", "trees", "grass"] | |
}; | |
// Create a grammar | |
var grammar = tracery.createGrammar(symbols); | |
// Set what they like | |
personA.like = grammar.flatten("#like#"); | |
personB.like = grammar.flatten("#like#"); | |
personA.say("I like " + personA.like + "."); | |
if(personA.like == personB.like) { | |
personB.say("I also like " + personA.like); | |
} else { | |
personB.say("I don't like that. I like " + personB.like + "."); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment