We're rapidly approaching a turning point. Up until now this has mostly been a learning exercise, making up technical techniques as we go along. Very soon we'll have all the tools at our disposal to complete the idea, when that happens it's all legwork and very little experimentation with the engine.
This article and the next are going to be about making the dialogue system work and that will be the last major string to our bow.
Dialogue then, how do we get our characters to talk to us? Dialogue is an entirely different and separate scripting system than the AI scripting we've been using so far. Each speaker has a dialogue file in a directory created for that purpose and we have to name the speaker in the bot's properties.
The easiest way to get this across is to work with an example. As far as our story goes the most important thing the player needs to know straight away is that she's on a timer and that timer will last about an hour. To do this I'm going to have the player start in the redoubt with Agnes, who is in mid-conversation with Fleet Support, trying to arrange a dropship to pick them up.
Fleet Support will be represented by an officer character from the original game who will appear as a hologram on the equipment in the centre of the room. These are the lines:
Agnes: This is Angels-Two-Five-Zero to Fleet Support requesting immediate pickup. We are hull-down and penned in by superior Izanagi units, over. Fleet: Negative Two-Five-Zero, all dropships are engaged with the evacuation, you're going to have to make it to the extraction point, over. Agnes: Fleet, we are all run out and nowhere left to hide. They'll be on us any minute, we need evac right now or we're toast, over. Fleet: We can't get a ship to you for at least an hour Two-Five-Zero, you're going to have to hold out, over. Agnes: Roger that Fleet, Two-Five-Zero out.
Straight away we put the situation to the player. You're stuck in a hole, the bad guys are coming, rescue won't turn up for an hour.
This is the first type of dialogue we have to figure out how to do, dialogue instigated by the AI script. First we'll set up the lines so that they /can/ be spoken, then we'll set up the AI script to call them at the appropriate moment.
Dialogue files consist of collections of 'nodes'. At the beginning of the file is the Root Node that provides the system with an easy look-up table for any particular dialogue file.
Here's the Root Node of Agnes' dialogue file:
[Root] Conversation=Introduction1
Yeah, that's it. Pretty boring, huh? All it does is tell us that there's a conversation with the name 'Introduction1' in this file. There are five lines that we want to add, so we'll need five more nodes, one for each line (sorry if this stretches your browser window, this is how it works):
[Introduction1] Speaker=Agnes SpokenMax=1 LongText=This is Angels-Two-Five-Zero to Fleet Support requesting immediate pickup. We are hull-down and penned in by superior Izanagi units, over. NextNode=Introduction2 [Introduction2] Speaker=Agnes SpokenMax=1 LongText=Negative Two-Five-Zero, all dropships are engaged with the evacuation, you're going to have to make it to the extraction point, over. NextNode=Introduction3 [Introduction3] Speaker=Agnes SpokenMax=1 LongText=Fleet, we are all run out and nowhere left to hide. They'll be on us any minute, we need evac right now or we're toast, over. NextNode=Introduction4 [Introduction4] Speaker=Agnes SpokenMax=1 LongText=We can't get a ship to you for at least an hour Two-Five-Zero, you're going to have to hold out, over. NextNode=Introduction5 [Introduction5] Speaker=Agnes SpokenMax=1 LongText=Roger that Fleet, Two-Five-Zero out.
The anatomy of a node goes like this:
First is the name of the node in square brackets: [Introduction1]. Next is the name of the speaker (Speaker=Agnes), a reference to a label defined in a bot's properties. You'll notice that all of the above nodes cite Agnes as the speaker, even when it isn't her speaking. I've nicked this idea from looking at the files used in the original game. What I think is happening is that by making the nodes of a particular conversation dependent on two independent bots you double the chance of something going awry, so by limiting both sides of the conversation to Agnes, I only have to worry about where Agnes is and what's she's doing. Something like that. It doesn't appear to have any real impact so I've set this conversation up in the same way as the example files.
The line tagged 'SpokenMax' is how many times this particular line is allowed to be presented during the game. Sometimes you want a line to be available more than once, but that isn't the case here, so all of the nodes in this conversation are set to SpokenMax=1.
'LongText' is the actual line that will be printed as a subtitle across the bottom of the screen. 'NextNode' specifies which node to go to next. If there is no NextNode specified, then the conversation will end.
Where this conversation is defined in the Root Node, we use the name of the first node of the conversation. Easy. Now we need to call the conversation called Introduction1 into life as soon as the game starts. We'll do this by initiating the conversation from Agnes' AI script.
After we broke all the script files up last time, the one we want is Agnes' first script, 01_Agnes_Begin.u2s.
All we have to do is add a dialoginitiate commannd:
//------------- Initialise ------------- :Initialise headtracking 0 ontrigger StartRun gotolabel StartRun message "Agnes - Introduction" //------------- Introduction ------------- :Introduction dialoginitiate Fleet Introduction1 sleep
This line:
dialoginitiate Fleet Introduction1
...finds the conversation called 'Introduction1' in the Root Node of Agnes' conversation file and starts it running. The 'Fleet' parameter defines who the conversation is directed at.
Time for a playtest to see if it works:
And it does. The last thing we need to do before we call this sequence complete is to find a way to get the hologram to go away once Agnes has finished talking to him. We do this by executing an ExitEvent at the end of the conversation. An ExitEvent is exactly what it sounds like, a named event executed just as the conversation ends. So the last node in Agnes' conversation now looks like this:
[Introduction5] Speaker=Agnes SpokenMax=1 LongText=Roger that Fleet, Two-Five-Zero out. ExitEvent=KillHolo
The event 'Killholo' is broadcast when the last node finishes. Let's set the hologram character to handle it when it arrives. This is what the hologram's AI script looks like:
ontrigger KillHolo gotolabel KillHolo sleep :KillHolo destroy
Which is pretty simple, the bot initialises by storing a label to go to on receiving the event KillHolo. When it gets the event it destroys itself, which sounds dramatic but it really just blinks out of existence.
Except it doesn't work.
I banged my head on this one for ages. I rewrote scripts, stripped them down, tested and re-tested and still the hologram refused to jump to the label in question. At one point I even removed the additional parameters in the bots display code and ended up with a 3 foot high fleet officer running around the place. That was pretty funny.
In the end I did the only sensible thing and start poking things randomly hoping by chance to hit on a solution. Let me make this clear, there was absolutely no reason why the above set up wouldn't work.
And I found it. Completely by accident. Apparently, the dialogue runs as a separate system to the AI scripting and it can override it's execution. As soon as Agnes' code reaches the 'dialoginitiate' statement the Fleet character quits running it's script until the conversation is over. Because Agnes initiates dialogue almost immediately the Fleet character hadn't even had chance to run its ontrigger statement and store the label name to jump to. The answer was to put a slight pause in Agnes' script:
//------------- Introduction ------------- :Introduction sleep 2 <-------- SLIGHT PAUSE :D dialoginitiate Fleet Introduction1 sleep
...this gives Fleet a chance to get his shit together (stop me if these technical terms get too much for you) and all is well. He blinks out of existence at the end of the conversation. Woo.
Next time, we'll look a the other type of dialogue, player-initiated dialogue and set up a basic ordering system that will let us tell the girls where to go and what to do when they get there.
Next: Part Seventeen (coming soon)