S
SirGiygas
Guest
So I have a dialog system wich, since recently, stopped breaking a line. I didn't change any code. Can you help me with this?
Here's the wrap script:
and here's the script that uses it:
Here's the wrap script:
Code:
///dialog_wrap(str, width);
/*
argument0: str -> The string to wrap (String)
argument1: width -> The maximum width of a line (Real)
Wraps the string so that it fits into width by adding newline
characters (#).
Returns the string with inserted line breaks.
*/
draw_set_font(fDialog); //Set the font to the one used in the dialog box
var str = argument0, width = argument1,
curPos = 1, goodPos = 1, lineStart = 1,
substr = "";
//Keep going until the string is the right width
while(string_width(str) > width && curPos <= string_length(str)) {
//Check for a space
if(string_char_at(str, curPos) == " " || curPos == string_length(str)) {
//Check if its too long.
substr = string_copy(str, lineStart, curPos - lineStart);
if(string_width(substr) > width) {
//Remove space
str = string_delete(str, goodPos, 1);
//Add newline
str = string_insert("#", str, goodPos);
//Change linestart
lineStart = goodPos + 1;
} else {
//String is good to here
goodPos = curPos;
}
}
//Next character
curPos++;
}
return str;
and here's the script that uses it:
Code:
var message = argument[0], msgstr = "";
//Save this for actions at the end
DialogController.lastMessage = message;
if(argument_count >= 2) { //Speaker
if(argument_count >= 3) { //Left sprite
msgstr += string(argument[2]) + SPR;
if(argument_count >= 4) { //Right sprite
msgstr += string(argument[3]) + SPR;
} else {
msgstr += string(noone) + SPR; //Add noone if there is no argument
}
} else {
//Both are noone if there is no argument
msgstr += string_repeat(string(noone) + SPR, 2);
}
if(argument[1] != "") { //Add speaker after the sprites
msgstr += argument[1];
}
}
msgstr += SPKR; //Add SPKR, even if there is no speaker
if(!string_count(OPTION, message)) { //Don't wrap the string if it's a list of options
message = dialog_wrap(message, DIAWIDTH);
}
if(message != "") {
while(message != "") {
var substr = "";
//Split the message into multiple boxes if it's too tall.
while(string_count("#", substr) < floor((DIAHEIGHT - DIAPADV) / string_height("A"))) {
if(string_count("#", message)) {
//Move the line to the substr from the original
substr += string_copy(message, 1, string_pos("#", message));
message = string_copy(message, string_pos("#", message) + 1, string_length(message));
} else {
//No more lines in the message, so add the whole thing
substr += message;
message = "";
break; //Force the loop to end
}
}
//Lengthen the pauses to be 3 `s long
substr = string_replace_all(substr, WAIT, '```');
ds_queue_enqueue(DialogController.dialog, msgstr + substr); //Add the part of the message to the queue
//String in queue looks like: 12@28@Name:Message
}
} else {
//Must provide handling for blank messages in case of no default value for dialog_input();
ds_queue_enqueue(DialogController.dialog, msgstr);
}