Introduction to dialogue
So far you've seen two types of scripts: town scripts and creature scripts. To make our non player characters talk, we need to add a third: talk scripts. Create a new file in the scenario directory called z0tunneldlg.txt, and copy the following:
begintalkscript; // Guard begintalknode 1; nextstate = 1; text1 = "You see a guard, sharpening his sword with a whetstone. He looks at you suspiciously."; text2 = "_My boss has a job for you. Talk to her._"; begintalknode 2; state = 1; nextstate = -1; question = "That's a nice sword."; text1 = "He grunts, and continues sharpening.";
Let's break it down line by line, the way we did for town scripts:
- begintalkscript; Required line at the beginning of all talk scripts.
- begintalknode ... ; Talk scripts are made up of nodes. Each node consists of a question you can ask, the response the non player character has, and any side effects.
- state = ...; and nextstate = ...; Nodes only become available when they match the current state. Once the text of a node is displayed, the questions that are available from state nextstate are displayed. nextstate for node 1 is 1, so all questions from nodes with state = 1 are displayed as the next question to ask. If nextstate is -1, that means there are no follow-up questions.
- question = ...; The question the player has to ask in order to see the text for this node. In nodes with state = -1, this line isn't required, but you often see designers using it to keep track of the character the talk node belongs to (instead of using a comment).
- text1, text2, ..., text8 = ... The lines of text that are displayed after the node's question is asked. These lines, like all strings, must be 254 characters long or less. text2 from node 1 has underscores in it. In the game, these are displayed as quotation marks (you can't use quotations marks in a strings, because quotation marks determine when a string begins and ends).
But wait! How does the game know what the first node to display for the guard is? We need to specific the guard's starting node in the Editor. Select the guard, click 'Edit This Creature', and set 'Cell 3' to 1. If you read the comments for the 'basicnpc' and 'guard' scripts, Cell 3 is used to set the initial talk node for each creature. Creatures with Cell 3 equal to 0 cannot be talked to.
![[IMAGE]](/static/tutorial/dialogue-intro/cell.jpg)
There's one other thing that needs to be set for the guard: its personality.