How to use the Dialogue Box for Lazy People

8

Attached Files

The following files have been attached to this tutorial:

.capx

dialogue-template.capx

Download now 259.41 KB

Stats

8,583 visits, 12,236 views

Tools

Translations

This tutorial hasn't been translated.

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Published on 22 Jun, 2016. Last updated 19 Feb, 2019

Are you too lazy to make your own dialogue box? Then welcome, this is the right place for lazy people (if you're not lazy you're welcomed too). I recently made a somewhat general dialogue box, and decided to share it with everyone.

To see the demo on the arcade click here. There is a Capx file too.

How to integrate the dialogue box to your projects

First download the dialogue_template project file provided with this tutorial and put everything inside your project. Then include the even sheet "Dialogue Events" whereever you want to display a dialogue.

The only things you'll have to modify are the animation of the avatar object, the animations of the box object, the SpriteFont object if you prefer to use another font, and of course the dialogues.xml file.

To display a dialogue, chosen by it's id, you have to call the function "dialogue" with the dialogue idea as a parameter. Call "dialogue" ("dialogue_id"). Wait until the variable dialogue_loaded is set to 1 before calling the function dialogue

You'll have to write other functions if you want things to happen during your dialogues.

How to write a correct XML dialogue file

This is the hardest part, but once you'll understand it, it will be very easy for you to write dialogues.

Let's see what is the structure of a dialogue file (it will be easier if you look at the source code).

    
    <?xml version='1.0' ?>
    <Dialogues>
    	<Dialogue id='' key_next='' key_faster='' key_up='' key_down='' key_skip='' skip_function='' first_line_id='' typing_sound =''>
    		<TextLine id='' id_next='' box_animation='' avatar_animation='' type='' begin_function='' end_function='' choice_number='' auto=''>text</TextLine>
    		<TextLine id='' id_next='' box_animation='' avatar_animation='' type='' begin_function='' end_function='' choice_number='' auto=''>text</TextLine>
    	</Dialogue>
    
    	<Dialogue id='' key_next='' key_faster='' key_up='' key_down='' key_skip='' skip_function='' first_line_id='' typing_sound =''>
    		<TextLine id='' id_next='' box_animation='' avatar_animation='' type='' begin_function='' end_function='' choice_number='' auto=''>text</TextLine>
    		<TextLine id='' id_next='' box_animation='' avatar_animation='' type='' begin_function='' end_function='' choice_number='' auto=''>text</TextLine>
    	</Dialogue>
    	
    </Dialogues>


I know it seems complicated with all these attributes, but we will break it down slowly.

You can see that there are 3 main components: <Dialogues> ,<Dialogue> and <TextLine>. We will review them one by one.

<Dialogues>

Contains all the <Dialogue> nodes (i.e. all the dialogues of the game), you only need one <Dialogues> node in your file, it doesn't have any attributes (yet).

<Dialogue>

Will correspond to one dialogue of your game. It contains one or several lines of dialogue.

Attributes:

- id [mandatory]: it's the name of the dialogue. It must be unique so you can call the right dialogue, using the function dialogue. Doing something like Call dialogue("id")

- key_next [mandatory]: The key code of the keyboard key to go to the next text line once the current one is display.

- key_faster [facultative]: The key code of the keyboard key to display the text immediately.

- key_up [facultative]: Only put if there will be choices in this dialogue. The key code of the keyboard key to select the first choice above the current choice selected.

- key_down [facultative]: Only put if there will be choices in this dialogue. The key code of the keyboard key to select the first choice below the current choice selected.

- key_skip [facultative]: The key code of the keyboard key to skip and end the current dialogue.

- skip_function [facultative]: The name of a function that will be called when the user skip the dialogue.

- first_line_id [mandatory]: the id of the first <TextLine> to be displayed.

- typing_sound [facultative]: The name of the sound effect to be played while the text is typed. The sound will be looped during this time.

<TextLine>

Correspond to one dialogue line and its properties. The text that will be displayed must be put between the two XML tags, like this <TextLine> text <TextLine>.

In your text, you can include variable names between brackets, that will then be replaced by their value. <TextLine> You have {gold} gold left <TextLine>

The variable has to be a key of the dictionary "DialoguesVariables".

Attributes:

- id [mandatory]: It must be unique and different than 'end'.

- id_next [mandatory]: The id of the text line to be displayed after the current one. Must be set to 'end' to end he dialogue.

- box_animation [facultative]: The animation of the dialogue box playing during the text line. If not given it will be the same as the previous text line (if it is the first text line and no animation is given it will be "Default").

- avatar_animation [facultative]: The animation of the avatar playing during the text line. If not given it will be the same as the previous text line (if it is the first text line and no animation is given it will be "Default").

- type [facultative]: For now, two values are possible, 'wait' and 'choice'.

If 'wait' is given, the text won't change until the global variable wait is set to 0.

If 'choice' is given the next line will be a choice line. The player will have to choose among different answers.

Here is an example of a <TextLine> with a 'choice' type.

    		<TextLine id='0' id_next='1' type='choice' choice_number='2'>
    			<Choice id_next='2'> Yes. </Choice>
    			<Choice id_next='3'> No. </Choice>
    		</TextLine>


- choice_number [mandatory if type is 'choice']: The number of choices of this dialogue line.

- begin_function [facultative]: The name of a function that will be called at the beginning of the text line.

- end_function [facultative]: The name of a function that will be called when all the text of the text line is displayed (not when the text line changes).

- end_dialogue_function [facultative]: The name of a function that will be called when the dialogue is over (when the dialogue box is destroyed). Only useful when the id of the textline is 'end'

NEW!

You can now put commands inside of your text, just like this:

"My text[wait] line is[pause] amazing."

By default I just included a wait and a pause functions but you can add any functions you want. For

"Another text line,[hello] another command."

In your project file you just have to create a function named "command_hello"

Conclusion

I hope you will find this useful, and tell me if there is a point you want me to clarify :)

.CAPX

dialogue-template.capx

Download now 259.41 KB
  • 3 Comments

  • Order by
Want to leave a comment? Login or Register an account!
  • this is cool but i can't figure out where to put the files and stuff when putting everything into my project. you just say 'do it' like that's enough, it's very confusing.

  • Hi bbenny93,

    Thanks for putting this together!

    I'm trying to study it so I can better understand how XML might help me in implementing a customized dialogue system of my own.

    Would you mind answering some specific questions about the expressions and functions you use? I think they're pretty remedial, but I'm having a hard time finding clear explanations elsewhere on the forums.

  • Thanks to your great work, that helps a lot~