This forum is currently in read-only mode.
From the Asset Store
Create complex dialogues with ease with this tool/template!
  • I'm trying to find a good way to give npc's dialogue.

    I think the best way to go about doing it would be to somehow make it so strings would look as follows:

    Hello, I'm an NPC.\pMy name is NPC.\pBlah blah blah,\nblah blah blah.

    I'd like \p to wait for the player to press a key, then clear the textbox and keep going. \n would more or less be the same as enter.

    How would I actually do that?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I do not actively use C2 (Have a business license though), but this method should be easy to port over to C2.

    Basically, I store dialogue in a JSON file and load the files (Via a 'GET' request) into memory when a new level is loaded. The JSON base structure is like so:


    the "messages" array stores the dialogue the NPC says. The "setState" property tells the script which index of "messages" to go to when the player advances through the dialogueTree. The "responseIndex" property tells the script which response text to display, stored in the "responses" array, with -1 meaning their are no player responses for that message.

    The "responses" array works the exact same as the "messages" array. It has a setState property and a "message" property. The "message" property is the actual text to display. The setState property sets the message index to that value, advancing the dialogue.

    Here is a (very) rough example of it in action: http://aurava.com/labs/dialogueTree/

    Once you have the basic structure down, then you can expand the JSON file and have advanced things, such as showing certain responses depending on a global variable or anything really.

    It is also very simple to implement, this is the draw text code, located in my update() function:

    this.font.draw( this.data.messages[this.currentIndex].message, x, y );
    // Draw responses, if applicable
    if(this.data.messages[this.currentIndex].responseIndex.length > 1 || this.data.messages[this.currentIndex].responseIndex[0] >=1  ){
                for (var i = 0; i < this.data.messages[this.currentIndex].responseIndex.length; i++){
                    var response = this.data.messages[this.currentIndex].responseIndex[i]
                    this.font.draw(this.data.responses[response].message, 80, 10 *i);

    Where: this.data is the parsed JSON file. this.currentIndex is the location within the dialogueTree file (Keeping track of which message to display)

    and here is the code for moving around within the dialogueTree file, not including the actual movement code which should be self explanatory anyway (Push down, add one to this.index. Push up, subtract one from this.index.)

    this.response = this.data.messages[this.currentIndex].responseIndex[this.index];
    this.currentIndex = this.data.responses[this.response].setState;
    this.index = 0;

    Where: this.index = the location of the cursor and this.response = the index value of the response the player chose.

    I believe Construct 2 comes with a simple AJAX plugin out of the box that has 'GET.' You can use that to download your JSON file. I am not sure if it has built-in compatibility to parse the JSON file out of the box, but I'm sure something exists.

    I'm sure someone could convert this into a Construct 2 plugin quite easily.



    EDIT: I just realized this was posted in the Construct Classic section (Whoops :D). The post above still applies, but instead of using 'GET' you can use XML or something and then just load the file directly.

  • Load a list file from a private vARIABLE of the npc FAMILY in question on dialouge trigger

    like so:

    delete all lines

    load from file apppath&"data\npc\"+VAR+".txt"

    set line to one and call dialogue function

    on dialogue function

    set the text box that displays the npc name to soemthign like gettoken(getlistlinetext(currentselection),1,"#")

    and then the main dilogue text to perhaps


    then on key press event select the next line and call the function again

    so a dialogue would look somethign like this




Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)