Indie Dev

Hello Guest!. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, sell your games, upload content, as well as connect with other members through your own private inbox!

Help with making line breaks

Bahamut20

Villager
Xy$
0.00
JavaScript:
var breaks = q.desc.split('\n');
     var newLines =[];
     for(var i =0; i < breaks.length; i ++){
       newLines = newLines + breaks[i]+' 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[i],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?

I think this is what controls the sliceText part:

JavaScript:
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
}
 
This is rather old but do you just mean \n? Which is a line break?

Unsure of whether that'd work for splits. If not I'll edit this however you can do it.
 
Top