Help with making new lines of text

var breaks = q.desc.split('\n');
        var newLines = [];
        for(var i = 0; i < breaks.length; i ++){
            newLines = newLines + breaks + ' breakLine ';
        }
        this.questBitmap.textColor = this.normalColor();
        var lines = this.sliceText(newLines, this.contentsWidth());
        for (var i = 0; i < lines.length; i += 1) {
            this.questBitmap.drawText(lines, 0, this.lineY, this.contentsWidth(), this.lineHeight());
             this.write();
        }
        this.drawHorzLine(this.lineY);
        this.write();
    }


I am trying to add line breaks to a string but my JavaScript skills are really poor and I could use some help. I am working with Gameus Quest System plugin which draws the quest description in this part of the script, however, it does not recognize \n as a line break but draws a space instead. I'm trying to fix that.


The snippet above is what I am using right now. My plan is to use the 'breakLine' part to identify the breaks and then turn them into actual breaks (which is what I'm having trouble with).


Any ideas?


Edit: I think this is what controls the sliceText part:

Code:
   Window_Base.prototype.sliceText = function(text, width) {
        var words = text.split(" ");
        if (words.length === 1)
            return words;
        var result = [];
        var current_text = words.shift();
        for (var i = 0; i < words.length; i += 1) {
            var word = words[i];
            var textW = this.contents.measureTextWidth(current_text + " " + word);
            if (textW > width) {
                result.push(current_text);
                current_text = word;
            } else {
                current_text += " " + word;
            }
            if (i >= words.length - 1)
                result.push(current_text) 
        }
        return result
    }
I didn't really look at it fully so this is just off the top of my head. It seems like instead of a newline '\n' character you want to just draw a blank line. The way it seems to work is it will draw each line one after the other and you just need to have it add a blank line at the appropriate time.  Again, I didn't really read the code fully so I could be way off base but hopefully this gives you another idea of something to try.
Have you found a solution for this? I'm also struggling with the lack of line breaks on Gameus Quest System.
Have you found a solution for this? I'm also struggling with the lack of line breaks on Gameus Quest System.



Yes, I did.


Find the following piece of code:


this.questBitmap.drawText(q.name, headerX, this.lineY, this.contentsWidth() - headerX, this.lineHeight());
this.write();


Then add this underneath.


// modification by Bahamut
var breaks = q.desc.split('\n');
var newLines = []; //declares the array
for(var i = ; i < breaks.length; i ++){
newLines = newLines + breaks + ' breakLine ';
}
// end of modification


Finally, change this line:


var lines = this.sliceText(q.desc, this.contentsWidth());


Replace "q.desc" with "newLines"


I think those were the all modifications I made. Let me know if that works.
Thank you very much! However, I believe there's a problem. Dreamweaver is accusing syntax error on the line:


for(var i = ; i < breaks.length; i ++){


If I put a 0 before the ; like this


for(var i = 0; i < breaks.length; i ++){


it works, but it only adds the word " breakLine " whenever there's a breakline, so I guess there's some code missing.


Once again, thank you for your help. I've been searching on the internet and it seems that you're the only one who requested this fix, which I find very odd for such an useful feature on this lacking area of RMMV (Quest Log).
Sorry I tried so many things I have a little bit of a mess. Apparently there was another change needed (not sure how the zero got erased there, was a copy-paste, but there is definitely a zero there).


I also modified the Window_Base portion, here it is:


/---------------------------------------------------------------------------------------------
// Window_Base
//---------------------------------------------------------------------------------------------
Window_Base.prototype.sliceText = function(text, width) { // modified by Bahamut
var words = text.split(" ");
if (words.length === 1)
return words;
var result = [];
var current_text = words.shift();
for (var i = ; i < words.length; i += 1) {
var word = words;
var textW = this.contents.measureTextWidth(current_text + " " + word);
if (textW > width || word == "breakLine") {
result.push(current_text);
if (word != "breakLine") {
current_text = word;
} else {
current_text = " "
}
} else {
if (current_text != " ") {
current_text += " " + word;
} else {
current_text = word;
}
}
if (i >= words.length - 1)
result.push(current_text)
}
return result
}




I will just attach the modified file, that's probably easier.

View attachment GameusQuestSystem.js
Thank you!! Now it works!


I just had to add an extra / on the beggining and add that dodgy 0 again.
So if anyone in the future is reading this, here's the fixed last code:


//---------------------------------------------------------------------------------------------
// Window_Base
//---------------------------------------------------------------------------------------------
Window_Base.prototype.sliceText = function(text, width) { // modified by Bahamut
var words = text.split(" ");
if (words.length === 1)
return words;
var result = [];
var current_text = words.shift();
for (var i = 0; i < words.length; i += 1) {
var word = words;
var textW = this.contents.measureTextWidth(current_text + " " + word);
if (textW > width || word == "breakLine") {
result.push(current_text);
if (word != "breakLine") {
current_text = word;
} else {
current_text = " "
}
} else {
if (current_text != " ") {
current_text += " " + word;
} else {
current_text = word;
}
}
if (i >= words.length - 1)
result.push(current_text)
}
return result
}




Huge thanks to Bahamut20!

Original thread: https://forums.rpgmakerweb.com/threads/help-with-making-new-lines-of-text.57400/