So, as we see in the previous chapter "Speech Text", you can make your characters speak in a nice way now. But one of the most important features of a point-and-click adventure game are the dialogue trees, where the player can react to choices offered by a non-playing character. This is slighty more complex to implement in your game, but a dialog selection is just an advanced version of a speech text, so don't worry.
In practice, when a dialogue starts, a UI shows up with multiple choices, to start a conversation with a character. Our game can have multiple versions of the dialog selection UI, in the same way than the speech texts, and each version can have multiple avatars, in the same way than the text display UI.
We will not speak about the esc scripting part of dialogs in this chapter, because you will need to know more about the esc scriting concepts to manage them correctly. But here is an example of what it look like so you can have a first idea:
? type avatar timeout timeout_option
- "I'd like to buy a map." [!player_has_map]
say player "I'd like to buy a map"
say map_vendor "Do you know the secret code?"
- "Uncle Sven sends regards."
say player "Uncle Sven sends regards."
say map_vendor "Here you go."
say player "Thanks!"
global_set player_has_map true
say map_vendor "You can't afford it"
say player "I'll be back"
say player "Nevermind"
say player "Nevermind"
As in speech texts, when starting a dialog, a type is specified (or not, in that case the type is "default"). An avatar can also be specified. There are two additional and optional parameters, "timeout" and "timeout_option", which allow to force a choice after some time if the player didn't choose quickly enough.
We will speak in detail about how to script dialogs in the "Dialog Trees" chapter of the "What you need to know as a game designer" section of this book.
So let's focus for now of the dialog selection type scenes, which are similar to the speech type scenes.
To configure the list of available dialog types, we edit the scene found in another dedicated list scene file, which is globals/dd_player.scn. Again, this is a ResourcePreloader node, meaning it preloads all the available scenes for each dialog type as a resource. The name of each preloaded resource will be used as the type name of the dialog. You should have one dialog available with the name "default", and add any additional dialog scenes you want to use.
A dialog selection scene itself is a somewhat complex scene, because it needs to be created dynamically by the dialog selection script. The root node is a Node2D with a script found in globals/dialog_dialog.gd.
It's mainly constituted by three parts:
An example scene can be found in ui/dd_default.scn, here is the complete structure:
The "anchor" container consists of another node structure that will contain all the dialog options, configured by the script. The structure is:
The dialog "item" is a small node structure inside the scene which provides a template of one dialog option, that will get duplicated for each option we need to show. The structure for the item is:
Additionally, we can have a node of type AnimationPlayer with name "animation". This player can have 3 animations, "show" and "hide", which will be played when the dialog is opened and closed, and "timer", which will be played when a timeout value is supplied. Note that when opening the example dialogue scene, the "hide" might have been executed, so the dialogue might be invisible. Try running the "show" animation first.
Finally, here is an example from our mini-game:
Il y a une erreur de communication avec le serveur Booktype. Nous ne savons pas actuellement où est le problème.
Vous devriez rafraîchir la page.