Spent a fair bit of time working on my game today. I tweeted
about one of the things I was working on, which was the NPC speech tree system in my game.
Though really, I was working more on the method of storing the strings and relationships for the speech trees. My game has a fairly extensive speech system in place already, though it is largely driven through a set of script utilities which can be called to do things like show a speech box, add response options, etc.
Instead of handwriting a bunch of scripts to leverage this, I went for a data driven implementation.
At first, I went with JSON, because I'm an idiot and I like to think that JSON is the solution to everything. Well, turns out writing JSON by hand is some trash, and I got real sick of that real fast.
Where I landed was YAML, which is much nicer to write by hand, and has similar structure to JSON, with the added bonus of references, which allows for reusability of data, which I needed for things like responses that may be used in multiple places.
I took those YAML files and wrote a small parser, which takes the yaml and converts it to GML scripts that use my game's speech engine. From there, I just import the script, and hook it up to the NPC in question, and boom, done.
I could take it one step further and bundle the yaml into the game, reading it in directly, but allowing for the compilation to GML gives me a bit more wiggle room. We'll see if I stick with that for the long haul.
Ultimately, I have something that looks like this:
- slug: intro
- hello, world
- this is some npc speech
- text: Cool!
- text: Lame.
- slug: outro
- Yeah, its kinda neato
- slug: outro_bad
- You're mean.
This super small example would have an npc say "hello, world". The next page of their speech is "this is some npc speech."
Following that, the player can choose between saying "Cool!" or "Lame." Picking "Cool!" prompts the npc to say "Yeah, its kinda neato." Picking lame promps them to say "You're mean". Which, you are.
Anyway, this is my simple approach to giving myself a reasonable way to manage what will ultimately be thousands of lines of speech strings. I don't think I need any fancy graphical editor or anything, but wanted to see what other people have done to solve this problem, as I know its a big one for everyone.