• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Displaying short dialogue

C

colcha

Guest
Hi I have a question about displaying some text dialogue.

I'd like for the player to be able to select a couple of dialogue questions and then display a few responses. I've recently learnt about arrays and seem to understand them now, but I'd like to do something a bit more complicated with them.

So far my game is using a 2D array to store some questions and responses, however where I hit a snag is when the npc response reveals some new information. I'd like this to generate a new question on the first menu at the bottom of the other questions.

What is the best way to do this?
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Personally, I'd have a "state" variable in the object displaying the messages. This would then be set to a value, such that (for example) 1 = initial dialogue, 2 = first question, 3 = second question, 4 = reply1, 5 = reply2, etc... You would then have a "switch" statement that checks this variable and displays the appropriate text.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Check out my asset, currently free while awaiting some updates. It's an extensive dialog system. Might be somewhat complicated if your new to game maker or programming.

https://marketplace.yoyogames.com/assets/2847/dsdialog
While we appreciate that you want people to buy your assets, please try to post and offer some constructive help apart from the link, as this is simply advertising and the user is asking for help with a specific problem and not a asking for a whole engine.
 
L

L0v3

Guest
Apologies for my advertisement. Here's a simple example of how one would create a simple dialog system from an old topic, link here:

http://gmc.yoyogames.com/index.php?showtopic=690589&hl=dialog#entry4949187

However, once you venture into the realm of branching dialog, it becomes a lot more complicated than displaying text in a sequence. You would have it create some choices also stored in an array after the dialog sequence ends, and having those choices act like buttons that start additional dialog branches once clicked. Here I would recommend using objects to store the information and store those objects in an array instead of the plain text.

For the desired effect you are describing, you would also need an identifier on a choice that once that choice is clicked the main choice hub which seemingly can be returned to would create an additonal choice.

For a sequence of events it would look like:
Hub - 3x Choices
1 is chosen with identifier x.
Check for x someplace, then create a new choice on hub.
Once whatever new branch you started ends, return to hub, where new choice now exists.
 
C

colcha

Guest
Thanks for the responses. I'll take a look at the file but it'll probably be a bit hard to grasp at this stage (experienced artist just learning to code games), so trying to keep things as simple as possible so I can figure out what each part is doing.

So at the moment I have an object that stores all the questions and allows me to select each one. This then accesses a script (switch, case etc) that tells each option to access the submenus (which are also created in the object). I can't quite work out what to put in there for the option in the sub menu to add a new entry to the main menu. Would I need to put something in "draw" to do this or would it be in the script?

Fortunately I don't need to go into complex dialogue trees - just for some of the answers to add a new question to the initial menu.
 
C

colcha

Guest
Right, I'm still a bit stumped with this, so I thought I'd post a bit of the code and can work out where I need to put the necessary functions to do this (I'm cutting chunks out to make this simple, so some variables might not be defined/control missing etc).

So first I create an object that defines the questions:

Code:
menu[0,0]=3;
menu[0,1]="Ask about this";
menu[0,2]="Ask about that";
menu[0,3]="Ask about something else";

menu[1,0]=1;
menu[1,1]="Question about this";
This accesses a script that defines what menu 1 does (I've not put in what the functions do or the second pages to keep it short)
Code:
switch(page) {
        case 0:
             switch(current) {
                case 1:
                      page=2;
                      current=1;
                break;
                case 2:
                break;
                case 3:
                break;
            }
        break;
}
I'll miss the step part out as I just define the control in there, but I then this is what I'm using in draw to display the questions.


Code:
for(i=1; i<=menu[page,0]; i+=1)
{
    draw_text(x + space, y + (i * space),string(menu[page,i]))

}
Now this works, but I'm not sure what and where I should be putting the code in to add (or just display) the "ask about something else" question. Basically only the first two questions are displayed, the player then selects "ask about this", the "question about this" is displayed on screen with the answer, then adds the "ask about something else" question to the main menu. If I'm going about this completely wrong then can also let me know - I'm here to learn and get this right.

Thanks.
 
O

Opticrow

Guest
I'd have a "state" variable in the object displaying the messages. You would then have a "switch" statement that checks and displays the appropriate text.
Surely it would be much more efficient to have a text variable, and only use a switch statement to update it. That way you're not iterating through a switch every single step, you're just reading from a variable.

So, this would be the script:
Code:
///Text_Update( id )
/*
Updates the dialogue via id
*/

switch argument0
    {
    case 0:
        {
        DialogueText = "Hey there!";
        } break;
    case 1:
        {
        DialogueText = "Wanna buy some magic items?";
        } break;
    case 2:
        {
        DialogueText = "Thanks for doing business!";
        } break;
    }

You'd update it like this:
Code:
//If ready to interact with player
if distance_to_object(obj_Player) < 50 and !DialogueOpen
    {
    //Say hi
    Text_Update( 0 );
    DialogueOpen = true;
    }
And the draw event would literally just be:
Code:
draw_text(x,y-30,DialogueText);
 
C

colcha

Guest
Thanks - where do I put the Text_Update( 0 ) in regards to the for loop that I posted? I don't have a player character in this part of the game (think static shop screen), so it's just dialogue options and this is always true.
 
O

Opticrow

Guest
Text_Update( * ) immediately changes the text on screen, so when the player selects an option, that's when you trigger it. The ID will depend on what the player selects.

So if the shop options are:
Ask about magical items
Ask about weapons
Ask about selling items

You'd set the switch up like this:
Code:
///Text_Update( id )
/*
Updates the dialogue via id
*/

switch argument0
    {
    case 0:
        {
        DialogueText = "Ah yes! We have quite the range in witchcraft! Follow me to the back!";
        } break;
    case 1:
        {
        DialogueText = "Unfortunately, we don't sell weapons here.";
        } break;
    case 2:
        {
        DialogueText = "This isn't a pawn shop, but I s'pose I could take a look";
        } break;
    }
And then if the player selects the first option, you run Text_Update( 0 ), if they select the second option, Text_Update( 1 ), etc!
 
C

colcha

Guest
OK I get how it's stored and how it accesses the information, but I was using a for loop before and I don't know how to change that to an if statement and for it to continue to do what I want. Everything I try is just bringing up errors so don't know where I'm going wrong.

Instead of

Code:
for(i=1; i<=menu[page,0]; i+=1)
{
    draw_text(x + space, y + (i * space),string(menu[page,i]))

}
am I just putting an if statement that included Text_Update? I don't see how that works with the menu. Forgive me but I've only been doing this a week and there's not much information on this that isn't in relation to a larger project.
 
Top