RPGDXThe center of Indie-RPG gaming
Not logged in. [log in] [register]
 
 
Post new topic Reply to topic  
View previous topic - View next topic  
Author Message
Mattias Gustavsson
Mage


Joined: 10 Nov 2007
Posts: 457
Location: Royal Leamington Spa, UK

PostPosted: Wed May 09, 2012 6:42 pm    Post subject: Dialogue system (source code) [quote]

A while back, I made a point-and-click adventure game, and one of the systems I developed for it was a simple script format for interactive dialogues. I've finally taken the time to clean it up and comment it a bit, as I will be using it for my new RPG as well, and I thought I'd share it, in case someone else has a use for it.

I wanted a format which is easy to read and edit, so I could work out my dialogue directly in the script files. For this reason, I didn't want to use an existing script language, with its pre-existing rules for syntax, so instead I created my own from scratch. It is in no way a full programming language - I prefer to keep all my code in C/C++, so it is merely a simple markup language.

Here is an example dialogue script, taken directly from my game:

Code:
[ShowPicture]
<O'Reilly> Have you seen this man around?
<Bambi> Yeah, I've seen him with some of the *girls*.
<O> Any idea where he might have taken her?
<Bambi> Probably to this *motel*... that's where he'd usually go....
#UnlockMotel#

[TalkToBambi]
^ Sorry to *bother* you, ma'am. I need to ask you some *questions*. @YouAcop
^ Well well well... ain't you a *classy* one. @Classy
^ Excuse me, do you know a woman by the name of Amber? @Amber
^^ I don't have any more questions right now. @EXIT

[YouAcop]
<Bambi> You a *cop* or something? Fuck off.
<O'Reilly> *Believe* me, I hate those *bastards* just as much as you do.
@RETURN

[Classy]
<Bambi> Errr.. No *offense*, pal, but you're not exactly one to *talk*.
@RETURN

[Amber]
<Bambi> I knew Amber. But Amber is *dead*.
@RETURN


The script is split into Conversations, and a conversation is defined by an ID within square brackets (eg. ShowPicture, TalkToBambi etc). The idea is that the code will start a specific conversation by stating its ID. A conversation consists of a number of entries, which can be any of the types Line, Option, Redirect or Event, and it will run until no more entries are defined, or until a Redirect with the ID "EXIT" is encountered.

Lines are the ones which starts with a character ID within angled brackets (eg. O'Reilly, Bambi etc). These are actual lines of speech, which are meant to be played out in sequence.

Options start with ^ or ^^ and are lines of speech which the player can choose between. They are followed by the ID of the conversation to proceed with when that option is selected. Options starting with double ^^ are permanent, which means they are available every time that conversation is played, while the ones starting with a single ^ can only be selected once (and are then removed from the list of options the next time it is displayed).

Events consists of just an ID surrounded by # (eg. #UnlockMotel#), and are used to communicate with the game code. If you want some event to happen, such as giving the player an inventory object, or setting an in-game flag, the way to do it is by sending a unique event which the game code can interpret and act upon. I deliberately made this part of the system very basic, as I find it much easier to debug things when a majority of the code is on the C++ side.

Redirects work like a GOTO statement. They are just a conversation ID prefixed by @. There are two IDs which are reserved for special purposes - EXIT (which tells the system to quit the current dialogue) and RETURN (which tells the system to jump back to the conversation that lead to the current one).

The code for this can be downloaded here:
http://www.colossusentertainment.com/forumref/DialogueSystem_1_0.zip

The main part of the code is the parser itself, which reads the dialogue files and provides an API to access its element. Also included is a reference implementation of a "player" for the dialogues - but this one will obviously be different for every game, as it needs to tie in with other game systems. For another example of a dialogue player, check out the source code for The Strangler.

As per usual, the code is public domain, so totally free to use in any way - I hope it comes in handy for someone :-)
_________________
www.mattiasgustavsson.com - My blog
www.rivtind.com - My Fantasy world and isometric RPG engine
www.pixieuniversity.com - Software 2D Game Engine
Back to top  
Post new topic Reply to topic Page 1 of 1 All times are GMT
 



Display posts from previous:   
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum