twisterghost

Last Login:
March 28, 2017
Warn:

Rank:
Moderator



User Profile
Follow

Hits: 154,591
Joined August 06, 2005
Games (19)

Elicti (Old version)
February 08, 2006
LOLOMGWTFBBQ
June 26, 2006
64Buddy
April 17, 2006
ludaBAD
April 20, 2006
NoobRageX
April 25, 2006
HummingBird
April 26, 2006
Elicti-Version 1.1.3
June 15, 2006
LOLOMGWTFBBTWO
July 13, 2006
SWP 1.5
July 31, 2006
Total Pwnage
August 21, 2006
Elicti: Patch 1.1.8
September 17, 2006
LOLOMGWTFBBQ3
August 25, 2006
AzNventure!
September 01, 2006
AzNventure2!
November 02, 2006
Spinning Squares
December 02, 2006
Elicti: 2.0.1
December 10, 2006
LOLOMGWTFBBQ4
December 25, 2006
King Cuko's Lost Gold
February 07, 2007
Kevin's Quest
January 01, 2007
Favorite Users


Speech Trees
Posted on September 05, 2016 at 21:39

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:

Code

prefix: speech_some_npc
speeches:
  - slug: intro
    pages:
      - hello, world
      - this is some npc speech
    responses:
      - text: Cool!
        slug: outro
      - text: Lame.
        slug: outro_bad

  - slug: outro
    pages:
      - Yeah, its kinda neato

  - slug: outro_bad
    pages:
      - 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.

~tg


I've actually been putting off working on that part myself. The furthest I've gotten is just displaying the NPC dialogue and have yet to do any of the character input stuff. :(
Posted by LAR Games September 05, 2016 22:27 - 6.8 months ago
| [#1]

Quote
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.


Not only writing JSON sucks, but the whole format sucks. It's too limited and looks very, very ugly. I prefer either storing data to Lua tables (probably impossible to read in GM:S) or xml. (Never heard of YAML)
Posted by Jani_Nykanen September 06, 2016 2:28 - 6.8 months ago
| [#2]

Quote
Quote
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.


Not only writing JSON sucks, but the whole format sucks. It's too limited and looks very, very ugly. I prefer either storing data to Lua tables (probably impossible to read in GM:S) or xml. (Never heard of YAML)

Unless I'm missing something huge, there's not really much of a difference between Lua tables and JSON objects, just some minor syntactic things (= instead of :, {} instead of [] for arrays). And whatever JSON's evils, it's an improvement on the giant verbose nightmare that is XML.

I'm quite partial to TOML for some purposes, but it can get confusing once you start nesting things. I think there's also something to be said for Lisp-style s-expressions as a data format -- they're like JSON but without all the extra colons and quotes.

Posted by F1ak3r September 06, 2016 3:46 - 6.8 months ago
| [#3]

Quote
Not only writing JSON sucks, but the whole format sucks.


I don't really agree with that. Writing by hand does suck, but JSON has been such a big player in working with APIs and between applications. Not only that, but it lends itself to being manipulated very easily in most languages, especially JavaScript (given well, the name). I work in JS for work pretty much all day every day, and JSON is the foundation of what our current product can do.

That said, it's not the catch-all that I sometimes think it can be, as evidenced here.
Posted by twisterghost September 06, 2016 8:42 - 6.8 months ago
| [#4]

Quote
And whatever JSON's evils, it's an improvement on the giant verbose nightmare that is XML.


That's no lie. XML can balloon so quickly compared to JSON.

I used to love XML for everything, but I've switched to JSON for as much as I can. I don't mind writing it by hand though, Sublime helps a good bit.

@F1ak3r: Ooooh, TOML looks neat. Cargo uses it too.
Posted by Cpsgames September 06, 2016 10:17 - 6.8 months ago
| [#5]

Okay, maybe I don't like JSON because I once tried use it for some purpose it couldn't be used, and that made me dislike the language (that and all those quotation marks...).
Posted by Jani_Nykanen September 06, 2016 11:15 - 6.8 months ago
| [#6]

Very interesting setup
And yeah importing YAML directly sounds like overkill
Posted by SpectreNectar September 11, 2016 12:56 - 6.6 months ago
| [#7]

Recent Activity
 
Active Users (0)