Mod Side Story : a walkthrough of a text dialog mod

  • 62 favourites


Attached Files

The following files have been attached to this tutorial:



Download now 174.52 KB


Download now 176.49 KB


Download now 178.38 KB


Download now 251.02 KB


8,902 visits, 21,484 views



This tutorial hasn't been translated.


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.

Part 2 : New types of Dialog

Now that we have our basic structure, we can follow up with new types of dialog.

We will first add a simple type of Dialog, the random dialog.

Then, we will add a choice Dialog, where the use will have to choose between 3 answers, and it will trigger actions.

Like in first part, once this system is implemented in game, you will just have to add Dialogs on the CSV, and trigger them in your game (we will explain that more in depth part 3).

2.1 Random Dialog type

The Random dialog is a random sentence said by a PNJ, selected in a pool of 3 possible speech.

We will use the same CSV as before, and put each sentence in a column : Part1, Part2 or Part3.

Here is how our CSV looks like right now :

Like before, we will continue to use the variables CurrentDialog, CurrentState, and just output a random Part :

I changed the way to output with a simple function, Dialog_output, that just writes the text in the Text object, so for a real implementation, we will just have to re-write the output function to display the text how we want it.

Now that we can handle the random dialog, we just have to call it when needed. Do you remember the important function in 1.3 : Start_Dialog ? It was the function that, depending on the dialog type would call the right function. For now, it only let us display Speech. We are going to add the Random type inside :

Ho, and did you see it yet ? I also added the "Initialize_Choice" function. Yes, indeed, it's time, let's head up to the next type !

2.2 Choice Dialog type

Like always, let's start by defining exactly what we want. A Choice dialog Type is a dialog where 3 sentences are present, and a cursor goes from one to another depending on user input. Also, the user can select one of those sentences, and an action should then be executed.

For now, we are going to go with a simple text cursor, moved with up and down, and a "enter" validation, all via keyboard. This is, of course, quite simple to change depending on the situation.

The choice type has only 1 waiting state, and can react 2 possible ways :

- it waits for user input until a choice is made

- if a user input is up or down, the current choice changes

- if a user input is Enter, the current choice is made, and the corresponding action is called.

Based on this, we will need a new static variable : the CurrentChoice.

We will also need to add actions for each choice in the CSV.

We'll discuss the content of the action columns later (2.2.3).

2.2.1 Waiting state output

During the waiting state, we need to tell the player what is the current selected choice. We will for this need to prepare the text to display. As we are going for a full text output for now, a waiting state should display something like :

    [ ] First choice
    [>] Second choice
    [ ] Third choice

We still have our functions to take what we need from the CSV, so let's do it, and build this function :

In the For loop, I build the local variable to output the text I need. I cut the instruction in 2 to be more readable.

The first line has :

    CurrentChoice = loopindex ? "[>] " : "[  ]"

This is a ternary condition. Basically, it is a IF THEN ELSE instruction, but inline. If you didn't know it, try to use it, it's quite useful in lots of situations and works like this :

     (Condition) ? (THEN) : (ELSE)

The waiting state is also the one where we wait for user input, and update the output. We are going to do exactly what we described in 2.2 introduction :

To avoid conflicts with the other inputs of the game, User inputs are inactive on load. We just activate it when there is a choice dialog on the screen.

The last step to have a correct output is now to "start" this car, initialize the system. This is the function called in the "Start_Dialog" function. You know, the public one ;) As before, we will just set the variable right, and display the state (Display_choice). We will also need to activate the inputs.

2.2.2 Making the choice

The last thing we have to handle is the "Enter" input, making the choice. Depending on the choice selected when Enter is pushed, we will call the corresponding action in the CSV. What we need to do is define what those actions are.

Let's take a look back to the actions I wrote down :

- The last choice is supposed to do nothing. This doesn't require anything.

- The second choice is supposed to call the function "blink". This requires to just know the name of the function to call.

- The first choice is supposed to call a dialog. This requires to know the ID of the dialog.

If you take a minute to think about it, you can imagine other situations like the first choice, when you will want to call a function with a parameter. In this case, we want to call the public function Start_Dialog with the DialogID as a parameter, so the specified dialog will play. In a real game, you maybe would want to start a specific quest, or a specific script, or anything. So we need to be able to call a function and pass a parameter.

Based on this, we will want actions of those forms :

nameOfAFunctionToCall : blink

nameOfAFunctionToCall__Parameters : dialog__1

The events will use some string manipulation to look for the double underscore presence or not, and will call the "Action"&CurrentChoice function with or without parameters, depending :

And finaly, the actions implementations :

As this group of functions will always have to be re-written in your game, I put them together for simpler implementation.

The blink action will make the Start button blink. The function will be called without parameters.

The "dialog__1" action will call the function dialog with the parameter "1", witch will then call the Start_Dialog function with the parameter "1", witch will start the dialog ID 1 aka the "random" dialog.

2.3 Second part conclusion

Well, it doesn't seem like much, but the choice type is maybe the one you are most likely to use.

In the next part, we will focus on multiple points. First we will start by implementing this mod in a game. I'll use a prototype of mine as an example and will explain, step by step, how to do it in any project.

We will also expand on the output function. Instead of just putting out text, we will use spriteFont, add a speed of speech so the dialog isn't instant, and will see from here.

If you want to test the part 2, let's head over here.

If you have specific questions on how to implement this or that functionality, we will cover it, so feel free to ask, and discuss it over here.

This part was written trying to explain how to think a new functionality in this system, so if you have dialogs you could use it even if all the features you need are in it. One point I'll add in the future is the possibility to have multiple dialogs at once.

See you soon for 3rd part !


  • Order by
Want to leave a comment? Login or Register an account!