PDA

View Full Version : My dialog system sucks! :D (help plz!)



Ferdi
September 29th, 2005, 07:07 PM
Right now I can only get my answers displayed when I have an item which was asked for in the dialog. I know that sucks, and I know what I'm doing wrong (wrong position in the hierarchy). I'm actually really tired right now and it was time to go to bed a couple of hours ago so maybe I'm just missing something. Anyway, can anybody have a look at my code and tell me how to do the hierarchy so that I can get my answers to display even if there is no request for an item? I hope I made it a bit clear cause I'm not thinking clear at all right now, sorry.

EDIT: This is just a raw setup to find out how a build a dialog system.


texts = [
["Do you have some (ITEM_RUM) for me?",
"(N)No I don't actually.",
"(N)No, the I drank it all! *Hickup*",
"(Y)Yeah, sure I do!"],
["Your mother is so fat... bla bla!",
"(Y)Ah, shut up!"]
];
var Dialog:Number = 0;
var Text:String = texts[Dialog][0];
var Woord:Array = Text.split(" ");
ITEMS = [
["ITEM_RUM","RUM", "TRUE"],
["ITEM_MAP_TREASURE","TREASURE MAP", "FALSE"]
];

var strippedItem:String;
for (i=0; i<texts[0][0].length; i++) {
if (Woord[i].charAt(0) == "(" && Woord[i].charAt(Woord[i].length-1) == ")") {
strippedItem = Woord[i].substr(1,Woord[i].length-2);
for(a=0; a<ITEMS.length; a++) {
if (strippedItem == ITEMS[a][0] && ITEMS[a][2] == "TRUE") {
for(b=1; b<texts[Dialog].length; b++) {
if (texts[Dialog][b].substr(0,3) !== "(N)") {
this.answer.text = texts[Dialog][b].substr(3,texts[Dialog][b].length);
}
}
}
}
}
}

Blackspirit
October 1st, 2005, 07:31 AM
Hmm, hard to read your code....



if (Woord[i].charAt(0) == "(" && Woord[i].charAt(Woord[i].length-1) == ")") {


This is checking for an item...yes?
But theres no else statement to check if the item isn't found.

Also the for loop doesn't keep checking, it only goes through once with the texts[0][0], it doesn't get to texts[1][0]....

Maybe I just don't get what its trying to do....:D