/* $Id$ Copyright (C) 1999/2000/2001/2002 Kai Sterker Part of the Adonthell Project http://adonthell.linuxgames.com This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY. See the COPYING file for more details. */ /*! \mainpage The Adonthell Dialogue Editor This document is a part of the Adonthell Developer's Reference. It describes the usage of the dialogue editor (dlgedit) and gives a few hints for writing well designed dialogues.

Contents

-# \ref page1 -# \ref page2 -# \ref sec21 -# \ref sec22 -# \ref sec23 -# \ref page3 -# \ref sec30 -# \ref sec31 -# \ref sec32 -# \ref sec33 -# \ref sec34 -# \ref page4 -# \ref sec41 -# \ref sec42 -# \ref sec43 -# \ref page5 */ /*! \page page1 Understanding the Dialogue Engine Before we start designing our first dialogues, lets have a look behind the concept of the dialogue engine. Understanding the basics will allow you to use the editor more efficiently and prevent you from trying to accomplish the impossible. First of all, what exactly is a dialogue? In our case, a dialogue is the conversation between the player and at least one NPC. The NPCs speech is usually followed by a number of replies for the player to chose from. The NPC will then react according to the choice. After that it is the player's turn again, and so on. Apart from player and NPC there is a third entity: the Narrator. Technically, it behaves like a NPC, but it has a completely different role. Usually it will decribe matters that are of importance to the player, but cannot be depicted by the game engine. Now that we've seen who may take part in a dialogue, we'll have a look at its organization. It will usually start with NPC or Narrator speech, to give the player something to react to. However, there is no need for a player reaction. Instead, the Narrator and various NPCs could go on and on (in which case the dialogue would either degenerate into a monologue or into a conversation between different NPCs). Player speech however will \b always be followed by either NPC or Narrator text, unless it ends the dialogue. Dialogues following the scheme above will remain rather static. The player may chose from a list of replies whenever it is his turn, but other than that everything remains the same in all circumstances. Therefore, the dialogue engine provides a few mechanisms to make dialogues more dynamic and adaptive to different situations. For one, NPCs and Narrator can have choises too. Whenever they have several options, they will randomly pick one. That may liven up the dialogue somewhat, but it also means a total loss of control. Therefore, each choice can be combined with a condition. Player, NPC and Narrator will only be able to chose those alternatives whose conditions evaluated true. As practically every aspect of gameworld and characters can be queried in a condition, it is possible to create dialogues that can adapt to many different situations. Such dialogues require lots of writing, of course. Therefore, dlgedit's main aim is assisting you with the complex structure of dialogues, so you can fully concentrate on the actual writing. As it tries to get as little in the way as possible, its usage is not always intuitive. However, the brief tutorial that follows should make you comfortable with most of its controls. \htmlonly
<< Main Page   Contents   An Example >>
\endhtmlonly */ /*! \page page2 An Example After the theory, something more practical now. \subsection sec21 The Dialogue This is a very simplistic Dialogue we want to model, but you will see that it is sufficient to demonstrate the basic functionality of the Dialogue Editor. \verbatim Npc: "Hello, I am Eric." Player: "I am Kai." or "Goodbye!" Npc: "Nice to meet you." "Fare well." Player: "Goodbye!" Npc: "Fare well." \endverbatim \subsection sec22 Creating the Dialogue Dialogues start with a NPC line, so that is what we add first. Simply left-click on the dialogue area of the Editor. A dialog window pops up that allows you to enter the text of the node. As you see, NPC is the default, so simply enter the line of dialogue ("Hello, I am Eric.") and press OK. What you will see when moving the cursor over the newly created node is the following:
\image latex step1.eps \image html step1.png
Now we add the player's response. To do this, left-click on the circle. It will appear in red to signal that it is the selected node. Now left-click on a location a bit further down. Again the Text Input Window pops up, this time with Player preselected, just as we want it. Enter the text ("I am Kai.") and press OK.
\image latex step2.eps \image html step2.png
Your screen should look like this. The NPC node is still selected, therefore drawn red, and the Player node is drawn blue, to distinguish it from NPC nodes. The arrow between them symbolises the flow of the dialogue . Since the player shall have two possible responses, we have to create another Player node, somewhere next to the first one. ("Goodbye!") Voila, the first two lines of dialogue are already done. Now right-click on an empty spot to deselect the NPC node and then select the first Player node. You see that it appears orange, so you know at the first glance that it is a selected Player node. Left-click somewhere below it, enter the appropriate text ("Nice to meet you."), confirm with OK and repeat the same for the second Player node. ("Fare well.")
\image latex step3.eps \image html step3.png
If your display shows something similar, you've done it :-). Now lines 4 and 5 of the Dialogue have to follow, but, as you have already noticed, they are just the same as a part of the existing dialogue. Would be nice if we could reuse that part, eh? Well, we can. All we need to do is linking the right nodes. Okay, lets dot it: Deselect the Player node and select the bottom left NPC node (or the node correspondenting to that one in your work). Then simply left-click on the Player node that needs to follow. And this is the complete dialogue:
\image latex step4.eps \image html step4.png
Of course this is a most minimalistic example, and there are many advanced techniques yet to be explored, like \ref page4 to your dialogue. But at least you should have learned how to operate the program. For detailed descriptions of the remaining features refer to the following chapters. \subsection sec23 The Result Now save (File->Save) and compile (Dialogue->Compile) the dialogue. You'll get a .py file, the Python dialogue script. In our example it will look similar to the following: \verbatim import dialogue # -- pygettext support def _(message): return message class untitled (dialogue.base): text = [None,\ _("Hello, I am Eric."),\ _("I am Kai."),\ _("Goodbye!"),\ _("Nice to meet you."),\ _("Fare well.")] # -- (speaker, code, ((text, operation, condition), ...)) dlg = [\ (None, -1, ((1, 0, -1), )),\ ("Default", -1, ((2, 0, -1), (3, 0, -1), )),\ (None, -1, ((4, 0, -1), )),\ (None, -1, ((5, 0, -1), )),\ ("Default", -1, ((3, 0, -1), )),\ ("Default", -1, ())] def __init__(self, p, n): self.namespace = globals () self.the_player = p self.the_npc = n \endverbatim You see, its a lot easier to use the Dialogue Editor than writing that code by hand. Of course, if you know what you are doing, you can edit this file afterwards. But usually, you should do any editing in the editor only. (See http://www.python.org for an extensive documentation of the Python scripting language.) \htmlonly
<< Understanding the Dialogue Engine   Contents   The Dialogue Editor >>
\endhtmlonly */ /*! \page page3 The Dialogue Editor After above example you should be able to start designing Dialogues right away. But for your convenience, and because some of the advanced editor features are not described yet, this section contains the complete reference guide. \subsection sec30 Command line Switches Although dlgedit is a graphical editor, there are a few commandline options for convenience. \par -c compile all SOURCES and exit
If the -c option is specified with a list of dialogue source files (recognizable by their .adlg suffix), these sources are turned into python dialogue scripts without invoking the graphical editor. \par -d print project directory and exit
A dialogue is usually assigned to a certain project, i.e a game. The project directory tells dlgedit where to search for things like character and quest data needed to compile dialogues. \par -j project specify a default project
Assigns the given project to new dialogues, or to dialogues that do not belong to a project yet. To properly compile dialogues, they usually need to belong to a project. Works in combination with the -c option. \par -p path specify a custom project directory
If your project/game does not reside in the default project directory (which can be queried with the -d option), you can specify an alternative path with this option. \par -v print version number and exit You may specify a list of dialogue sources on the command line. Unless the -c switch is used, all of them will be opened in the editor. If no sources are given, it will start with a new, blank dialogue. \subsection sec31 The Main Window \anchor diaare
\image latex dlgedit_main.eps "The main interface" \image html dlgedit_main.png "The main interface"
\par 1. The Dialogue Area This is where you create the outline of the dialogue; what lines of text exist and how they are linked to each other. Most of the work is done with the mouse, but there are also a few shortcuts on the keyboard and some functionality is only available through the keyboard. \par The actions taken when a mouse- or keypress occurs depend on the current selection (none, circle, arrow) and the position of the cursor. The table below shows all possible constellations:
\htmlonly \endhtmlonly \htmlonly \endhtmlonly \htmlonly \endhtmlonly \htmlonly \endhtmlonly \htmlonly \endhtmlonly
\b Left-click \e Nothing \e selected \e Circle \e selected \e Arrow \e selected
\e on \e empty \e space Create new Circle Create new Circle \& link with selected -
\e on \e Circle Select Circle Link with selected -
\e on \e Arrow Select Arrow - -
\latexonly \hline\hline \endlatexonly \b Middle-click \e Nothing \e selected \e Circle \e selected \e Arrow \e selected
\e on \e empty \e space - Edit selected Circle -
\e on \e Circle Select \& edit Circle Edit selected Circle -
\e on \e Arrow Select Arrow Edit selected Circle -
\latexonly \hline\hline \endlatexonly \b Right-click \e Nothing \e selected \e Circle \e selected \e Arrow \e selected
\e on \e empty \e space - Deselect Circle Deselect Arrow
\e on \e Circle - Deselect Circle Deselect Arrow
\e on \e Arrow - Deselect Circle Deselect Arrow
\latexonly \hline\hline \endlatexonly \b Return \e Nothing \e selected \e Circle \e selected \e Arrow \e selected
\e wherever - Edit Circle -
\latexonly \hline\hline \endlatexonly \b Del \e Nothing \e selected \e Circle \e selected \e Arrow \e selected
\e wherever - Delete Circle and its Links Delete Arrow
\latexonly \hline\hline \endlatexonly \b Esc \e Nothing \e selected \e Circle \e selected \e Arrow \e selected
\e wherever - Deselect Circle Deselect Arrow
\par Further key-commands are \b c, which centers the view on the selected Node if it lies in the outer 20% of the Dialogue Area, the \b Cursor \b Keys and the \b Numpad to scroll the dialogue and finally \b Tab to select the next Node (That is, the next node in the editors internal data representation, not the next node on the screen!). Moving the mouse close to the Dialogue Areas border will also scroll the dialogue, and when dragging the mouse with left button pressed, you can select multiple Circles, for example to delete all of them at once. \par 2. A Node with additional code An exclamation mark (!) inside a circle means that the node contains commands other than just a line of text. What commands that may be in detail is explained in the \ref edit "Edit Dialog" description. \anchor indlin \par 3. An indirect Link Whenever a node with indirect links is \ref selcir "selected", they are highlighted in purple. Indirect links are equivalent to a normal link between selected node and the node the indirect link points at, but to avoid arrows criss-crossing over the whole Dialogue Area, it's often better to use an indirect link. The number inside Circles tells how many indirect links they have. \note This feature is deprecated and will be removed soon. Full downwards compatibility will be remained by automatically converting indirect links when loading old dialogues. \par 4. Highlighted Node Nodes below the mousepointer appear in green to give you some feedback what action a click will start at this point. \anchor selcir \par 5. Selected Node Selected Player nodes are drawn orange, NPC nodes red. Furthermore, the \ref inspre "Instant preview" shows their text as well as that of their predecessors and followers. \par 6. Tooltip Whenever a Circle is below the mousepointer, a tooltip with its text appears to make it easier for you to find a certain position in the dialogue. \anchor prenod \par 7. Text of preceding Nodes All the different lines of text that may preceed the \ref selcir "selected circle". The colour of the entries gives some information of the type: Blue text denotes lines of the Player, black text lines of the NPC; the Narrator appears green. Somewhat dimmed lines mean that the Circles are connected by \ref indlin "indirect links". \anchor inspre \par 8. The Instant preview This shall give a first impression of what the Dialogue will look like in the game. Basically it displays the text of the selected circle, together with all preceeding and following text. With this you should be able to judge whether all the combinations of text fit well together. Furthermore, by clicking on a line of text, the attached Circle is selected, meaning you can browse through the whole dialogue. Note that additional code of Nodes won't be taken into account, so in the game, the dialogue might be slightly different. \par 9. Text of selected node Again this is colour-coded: as in the \ref diaare "Dialogue Area", orange text means a Player line, red text a NPC line and green is the Narrator. \par 10. Text following the selected node Text following the selected Node. The colours are the same as for the \ref prenod "preceding nodes". \latexonly \newpage \endlatexonly \subsection sec32 The Edit Dialog
\image latex dlgedit_edit.eps "The Edit dialog" \image html dlgedit_edit.png "The Edit dialog"
\par 1. Edit Circle's Text When you create a new Circle, you should attach some text to it. This is done on this page. Simply type the text into the entry. Player text will be displayed blue, NPC text black and Narrator text in green. You can switch between the three with the \ref radbut "radiobuttons". \anchor edit \par 2. Conditions for the Node On this page, you can specify a condition which then decides whether this line of text will be available in the game or not. In fact you may enter any valid Python code, but the result may be unpredictable; so to be on the safe side, the code you write here should be a single (but not necessarily simple) if statement, like \par \verbatim if condition_1 == 1 and (flag_1 + flag_2) <= 10: \endverbatim \par You may also use elif and else statements, but again the results might be unpredictable, unless you restrict yourself to a single if and else. \anchor variab \par 3. Set and/or change Variables Here you can enter a variety of Python code. In contrast to the Condition code, where your code decides whether text is displayed or not, this code is executed if the line of text is displayed (in case of NPC text) or selected as response (in case of Player text). Use the code you enter here to change quest objects, NPC or Player attributes, etc. See the section about additional \ref page4 "Python code" for a description. \par The green page label tells you at a glance that this Circle contains some variable code, but neither Conditions nor miscellaneous Commands. The Text-page's label will always be black, as text isn't really optional. \par 4. Actions Here are just a few shortcuts that create code as you can enter in the \ref variab "Variables Tab". Currently, only the Loop command works. When activated, the Node will not be marked as used once it appears in the conversation, and thus may occur several times. \anchor radbut \par 5. Assign text to Narrator, NPC or Player Use the Radiobuttons to assign the Circle either to the Player, the Narrator or to a NPC. The Editor tries its best to guess to whom this line of text shall belong, but as long as it can't read your thoughts, you'll have to correct it sometimes. \par 6. Set NPC You can select the NPC who shall speak here. When using default, this will be the NPC this dialogue is assigned to. In case of a conversation between multiple NPC's, you might want to chose somebody else though. Note that only those NPC's are available that are currently in the character.data file in your adonthell-data directory. Use charedit to change this file. \par 7. Set NPC's mood Here you can specify what picture of the selected NPC the player gets to see. This feature needs to be implemented yet. \par 8. Annotation Here is some room for personal notes of all kind. Since a dialogue can get quite complex, you really should add some comments, so that other people as well as you can easier understand what is going on. \latexonly \newpage \endlatexonly \subsection sec33 The Run Dialog
\image latex dlgedit_run.eps "The Run dialog" \image html dlgedit_run.png "The Run dialog"
\par 1. The conversation so far The top part of the Dialogue test window will display the conversation you had so far. As known from the Editor, Player lines are displayed blue, NPC lines black. \par 2. The current NPC line The NPC's reaction to your last speech is displayed in red. If no responses of the player are available, click on this line to continue the conversation. \par 3. Your possible responses Usually, a line of NPC text will be followed by one or more responses, the player can chose from. Simply click on the text you wish to say and the dialogue will continue. \par 4. Restart this conversation Runs the dialogue from the beginning. This will also reload the dialogue in case it has changed on disk. \par 5. Debug this dialogue Opens the debug window if it is not already open. \subsection sec34 The Debug Dialog
\image latex dlgedit_debug.eps "The Debug dialog" \image html dlgedit_debug.png "The Debug dialog"
\par 1. Display local variables This tab shows the current dialogue's local variables, if that dialogue was compiled with debugging enabled and is currently running. Local variables are only available as long as the Run window is open. Further they are reinitialised when restarting the dialogue. \par 2. Display character attributes Here you can browse through all characters (and their attributes) in the character.data file in your adonthell-data directory. Unlike local variables, character attributes remain valid as long as the dialogue editor is running. Changes made to them will survive until the end of the editing session. In a future version of dlgedit, it should be possible to revert the attribute to those of the character.data. \par 3. Display quest attributes This tab shows all quests available in the quest.data file of you adonthell-data directory. The same rules as for the character attributes apply here. \par 4. The debug tree The actual attributes are shown in a tree. Unchanged attributes are displayed black, changed ones in green and deleted ones in red colour. You can change an attributes value by leftclicking on the attribute's name. To delete an attribute, assign a value of zero to it. To add a new attribute, simply click on the parent you want to add the attribute to. \par 5. Run dialogue Click here to run the current dialogue. This opens the Run Dialogue window in case it isn't open already. \htmlonly
<< An Example   Contents   Adding Python Code >>
\endhtmlonly */ /*! \page page4 Adding Python Code From the \ref sec23 "tutorial" you might have seen that each dialogue gets compiled into a python class which then is fed into Adonthell's Python interpreter to execute it step by step. Given the flexibility of Python, it is only sensible to use it to achieve more than simple static dialogues. In brief, Python makes it possible to reflect the gameworld's current state in a dialogue, and also to change that state depending on the player's behaviour throughout the dialogue. As you have learned above, you can enter additional Python code at various places of the dialogue: - into the constructor and destructor of the dialogue class. - directly into the text. This code has to be enclosed in braces {} and should return a string. - as a condition that decides whether a chunk of dialogue is displayed or not, - and finally you can add code that is executed after a piece of dialogue has been displayed. This section tries to give an overview of the possibilities additional Python code offers for the conversation with NPC's. One day there'll be some document discussing the Python scripting abilities of Adonthell in general. \subsection sec41 Embedded Code The dialogue engine allows to embed a function call into a line of text and will insert whatever string this function returns in place of the function. This only works for methods defined in the custom function window (Dialogue->Functions or \b Ctrl+F). It mustn't take any arguments and should return a string. For example, the method \verbatim def hello_world (self): return "Hello world!" \endverbatim can be used in the text "This will print: {hello_world}" to produce "This will print: Hello world!". Of course for this to make sense, such a method should return one of several strings according to the current situation. Note that this code is always evaluated whenever the line of text is displayed, no matter whether it gets selected by the player or not Apart from that, there are the \$name and \$fm{text_a/text_b} macros. \$name will be replaced with the player's name at runtime, whereas \$fm{/} will cause text_a to be displayed if the player is female or text_b in case the player is male. \subsection sec42 Local Variables For more advanced dialogues it might be necessary to define local variables. They belong to the dialogue class and are addressed as self.variable. Local variables are only accessible from within the dialogue itself and thus are only available as long as the dialogue is running. They are freed at the end of the dialogue. What for are they then? Basically they can be used to track the player's path through the dialogue. Information he may or may not have received could enable or disable additional choices at a later point in the same dialogue, but how does the dialogue engine learn about that. The solution is to use local variables. So when the player receives the special information you'd add the following variable code \verbatim self.special_info_gained = 1 \endverbatim and later on, you base the special choice on following condition: \verbatim if self.special_info_gained == 1: \endverbatim Note that you need not define a variable before you use it. Undefined variables are assumed to have the value 0, so in above example you needn't do anything about the case where the player doesn't get that special information. In many situations, it will be necessary that information survives an individual dialogue. That is where persistent variables come into play: \subsection sec43 Persistent Variables The state of the gameworld, of each NPC and the player are also accessible from a dialogue script. The full details should be discussed in a general scripting doc, but unless this has happened, here are the bits relevant for the dialogue engine. The state of the gameworld is conserved in the various quests. All quests are stored in the global data::quests dictionary. To retrieve a certain quest you'd write \verbatim myquest = adonthell.gamedata_get_quest("quest_name") \endverbatim Particular attributes of myquest are retrieved/set via \verbatim myattribute = myquest.get_val ("attribute_name") myquest.set_val ("attribute_name", ) \endverbatim To save you some writing, dlgedit recognises the following shortcuts: \verbatim myattribute = quest_name.attribute_name quest_name.attribute_name = \endverbatim Characters are treated in the same way. They are retrieved with adonthell.gamedata_get_character() and their attributes are also changed via the get_val()/set_val() functions. Even the shortcuts are the same. Instead of quest_name you'll have to give the character's name, e.g. \verbatim # character names containing blanks work too! Bjarn Fingolson.attribute_name = \endverbatim As an addition, the member variable the_player always points to the player character and the_npc to the npc the dialogue is assigned to. Of course you can do more than just read or change character and quest attributes. For example, you could change an NPC's schedule, or assign a different dialogue: \verbatim # you can access any character you want ... bjarn = gamedata_get_character ("Bjarn Fingolson") # .. and completely change his behaviour bjarn.set_schedule ("new_schedule") bjarn.set_dialogue ("new_dialogue") \endverbatim In fact, you have access to almost the complete Adonthell API, so there is much more you can influence than just the characters. Take a look at the Developer Documentation for the numerous functions you have at your command. \htmlonly
<< The Dialogue Editor   Contents   A Guideline for writing Dialogues >>
\endhtmlonly */ /*! \page page5 A Guideline for writing Dialogues After taking a look at the technical side, it's about time to give some hints on the actual dialogue creation. Although it might take a little while to get used to the editor itself, the real difficulty lies in the writing of high-quality dialogues. What follows are mainly personal experiences not the ultimate wisdom, but for the sake of consistency you should keep these points in mind when doing dialogues for Adonthell. You shouldn't consider them as strict rules, though. If you have a good reason to break them here and there, feel free to do so. \par Describe the NPC At the beginning of the dialogue, a short description of the NPC's mood or other features that would be obvious to their counterpart but cannot be portrayed by the game engine can give the player an idea how to deal with that character. It also enables us to give each NPC an individual touch thus adding more flavour to the game world. \par Leave the thinking to the player All the information contained in a dialogue should be kept in the NPC's part, whereas the player's part should contain as little hints as possible, and no information the person in front of the screen cannot deduce from previous dialogue(s). After all, part of the fun of playing the game comes from making connections between information given by various NPC's. Therefore, a player's answer may reveal the correct result of the thinking process, but it shouldn't give any (lengthy) explanations. \par Avoid single choices A single choice is no choice and rather boring. The reason for writing dlgedit is exactly this point. Adonthell is no self-running demo, but an interactive game, and interactivity requires that the player can choose from different alternatives. That doesn't mean that you can't have lengthy monologues of the NPC. However, if there is only one choice for the player, you might as well leave it away and let the NPC go on without interruption. \par Keep the player's text neutral Bear in mind that different players will have different feelings in the same situation. And unless you don't give the player the chance to chose an answer that comes close to his or her own personality, you should try to leave (strong) feelings away. Of course, depending on the underlying role playing system, you might present players with choices according to their alignment or behaviour in previous situations. \par Keep the text short Since there is only limited space in the game's dialogue window, you should limit the amount of text displayed a time. NPC text should fit entirely into the window, meaning it should not exceed 4 lines in the \ref sec32 "edit dialog". Longer text can be distributed over several nodes. Player text should take a single line, 2 at most, so that several choices fit into the dialogue window. \htmlonly
<< Adding Python Code   Contents  
\endhtmlonly */