Dialogue

For questions about using Classic.

Post » Sat Feb 16, 2013 5:42 am

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?
B
1
G
3
Posts: 4
Reputation: 833

Post » Mon Feb 18, 2013 1:46 pm

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:

http://aurava.com/labs/code/dialogueTree/dialogue.txt

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:
[code]
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
               this.font.draw(this.data.responses[response].message, 80, 10 *i);
            }

        }
[/code]
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.)
[code]
this.response = this.data.messages[this.currentIndex].responseIndex[this.index];
this.currentIndex = this.data.responses[this.response].setState;
this.index = 0;
[/code]
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.

Best,


Ty.

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.lTyl2013-02-18 13:58:00
B
4
S
1
G
3
Posts: 10
Reputation: 1,159

Post » Mon Feb 18, 2013 4:46 pm

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
(getlistlinetext(currentselection),2,"#")
then on key press event select the next line and call the function again

so a dialogue would look somethign like this
NPC#HELLO, DAVE#
PLAYER#TELL ME THE WAY TO THE LOST CAVERNS#
NPC#I CAN'T LET YOU GO THERE, DAVE#
B
18
S
4
G
1
Posts: 413
Reputation: 2,512


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 4 guests