Tutorial: How to make your own icon-based dialog system

Started by Chrille, Wed 23/04/2003 18:26:28

Previous topic - Next topic

Chrille

It's a messy tutorial featuring several typos, but hopefully it'll make sense ;).
Okay, an icon based dialog system is easy to set up if you're somewhat experienced with AGS scripting. Here's one way to do it:



1. First of all. I think you should use a custom inventory GUI for your game, you'll also need another GUI with a inventory window for the Dialog Icon Gui, since each dialog option/icon is an inventory item. Both the inventory and dialog gui should prefarably be set to  Visible: Script Only.



2. You can probably use the regular inventory click system, but I chose to Handle Inventory Clicks In Script (check in General Settings/Game Options. You'll also need to use a GlobalInt, this will be used to check if it's the inventory GUI or the dialog GUI that is currently open.



3. Create a new character, set its script name to DIALOG or something like that. Check the "no interaction" box in the character's settings and set his coordinates to somewhere outside the screen. Then add a on_event function to your global script if you havn't already. There is more information about it in the manual. Here's what it will look like:

function on_event(int event, int data) {
if (event==ENTER_ROOM) {
character[DIALOG].room = character[ X ].room;
}
}

Where X = is the script name/character # of your player character. What this does is everytime the player moves into a new room, the DIALOG character will move into the same room. This is very useful and the reason why will be explained later. While you're at it, add an integer to the top of the script, something like "int talkingto"



4. You will need to create some custom functions. You can copy it directly from here:

function OpenDialog() {
SetPlayerCharacter (DIALOG);
SetGlobalInt (X,1); // X is the number of the inventory/dialog control GlobalInt
game.items_per_line = #;
game.num_inv_displayed = #;
game.top_inv_item = 0; // only necessary if your dialog gui doesn't have a scroller
InterfaceOn (Z); // Z is the number of your dialog gui
}

Instead of using the RunDialog function, you run this everytime you talk to a character. It will set the player character to the DIALOG character and open the dialog GUI, where Z is the number of your dialog GUI. The game.items_per_line and game.num_inv_displayed settings are very important if your dialog GUI window is bigger or smaller than the inventory GUI window. Set these to match the dialog gui window if such is the case. The X is the number of the GlobalInt you're using to check which of the inventory/dialog gui is on. The game.top_inv_item part is only necessary if your dialog gui doesn't have a scroller. Because if it doesn't and you scroll down in your regular inventory window and then open the dialog gui, the current line might be set too far down preventing you from seeing the dialog option inventory items. So game.top_inv_item = 0; puts all the dialog options back into view.



5. The second custom function you'll need is:

function CloseDialog() {
InterfaceOff (Z); // Where Z is the number of your dialog gui
SetPlayerCharacter (Y); // Where Y is the ID of your player character
SetGlobalInt (X,0); // X is the number of the inventory/dialog control GlobalInt
game.items_per_line = #;
game.num_inv_displayed = #;
}

This function will be run everytime you cancel/close a dialog. It will close the dialog window and reset the normal inventory window settings. Set the game.items... and game.num... settings for the regular inventory window.



6. The third custom function you'll need to create is:

function RunDialog() {
InterfaceOff (Z); // Z is the number of your dialog gui
SetPlayerCharacter (X); // X is the ID of your player character
}

In this function, all of the game's dialog spoken using the icon dialog system will be written. You'll therefore need to check which dialog option/icon the player clicked on by adding the following to the RunDialog function:

if (game.inv_activated==#) { // # is the number of the inventory item (dialog option) clicked
}

In Revenants, since you'll be able to ask every character about every dialog topic you bring up, I use the following method to check which character you're talking to. Remember the "int talkingto" part I mentioned in step 3? When you run the interaction for talking to a character, you will need to set the talkingto integer to the # ID of the character you're about to talk to. It will look something like this:

talkingto = #; // Where # is the number of the character you're talking to
OpenDialog();

This way, you can easily control what each character has to say about each dialog topic. Here's an example of what the RunDialog function might look like after a while:

function RunDialog() {
InterfaceOff (Z); // Z is the number of your dialog gui
SetPlayerCharacter (X); // X is the ID of your player character
 if (game.inv_activated==2) { // Topic:  Key
   if (talkingto==5) { // Billy Schlong
   DisplaySpeech (PLAYER,"Do you have the key to the chest o' stashed away smut?");
   DisplaySpeech (5,"Yep, here you go");
   AddInventory (666);
   }
   else { // Any character who hasn't got anything to say about the topic
   DisplaySpeech (PLAYER,"Do you have the key to the chest o' stashed away smut?");
   DisplaySpeech (talkingto,"I have no idea what you're talking about!");
   }
 OpenDialog(); // This opens the dialog window again after the current conversation is over.
 }
 if (game.inv_activated==1) { // Topic: Stop Talking
 DisplaySpeech (PLAYER,"Gotta go, bye");
 DisplaySpeech (talkingto,"Cya");
 CloseDialog(); // This closes the dialog window, you'll need to talk to the character again to open it.
 }
}


7. Now for the final part. In the game's on_mouse_click function, you'll need to set up the inventory clicks (LEFTINV) and/or (RIGHTINV). You'll need to use the GlobalInt mentioned in step 2 to check whether you're clicking on a item in the inventory window or the dialog window. Here's what it might look like:


if (button==LEFTINV) {
if (GetGlobalInt(X)==0) { // Inventory Window: X is the number of the inventory/dialog control GlobalInt
SetActiveInventory (game.inv_activated);
}
else if (GetGlobalInt(X)==1) { // Dialog Window: X is the number of the inventory/dialog control GlobalInt
RunDialog();
}
}


8. The functions should be placed in the following order, otherwise the script will probably not compile:

OpenDialog()
CloseDialog()
RunDialog()
on_mouse_click()


Tadaa! You're all done. That is, unless I forgot to mention something. As you can see there are several ways to do this and it's very easy to customize to fit your game. You can control which dialog topics that show up for which characters by using integers or using a separate character as an inventory for each character in the game.
GASPOP software
http://www.gaspop.com

Snake

Grim: "You're making me want to quit smoking... stop it!;)"
miguel: "I second Grim, stop this nonsense! I love my cigarettes!"

jannar85

It's the dialogue tree, which is seen in Sam&Max, Broken Sword, and Discworld 1 and 2. ;)

Thanks Chrille. I will probably make a template out of this.. Not sure.. Too busy, but I'll see!
Veteran, writer... with loads of unreleased games. Work in progress.

SMF spam blocked by CleanTalk