How do I draw a text in costum menu with color change and new line?

Hello fellow RPG-Makers,

I have a costum menu and want to display item descriptions.
The drawText method will not suffice, because I need new lines and changing of textcolor.
Is there an easier way for me to display a costum text, than writing my own text interpreter code?

For example:

Item description in RPG Maker:

"This is a really cool [changeColor] item [\changeColor]. \n \n Additional information about this item."


Item description in-game:

"This is a really cool item.

Additional information about this item."

Am I missing a function, the game already uses for such tasks? I know you can change colors in the message windows,
but you can't create new lines. Am I going to have to create my own method to draw costum text like this in my costum
menu?

As always,
thank you in advance for your advice!

Kind regards,

Lanzy
you can use my TF function for it, but if you want a much nice one, you can use
TSR_TextColorAddon which extends it much wider and better than the one I have.

you can even do menu, skills, items, message, etc 🙂
you can use my TF function for it, but if you want a much nice one, you can use
TSR_TextColorAddon which extends it much wider and better than the one I have.

you can even do menu, skills, items, message, etc 🙂

This will save me so much time. Thank you kindly sir!

Now I only need a solution for the new line problem within the text.
I think you probably want the drawTextEx function, rather than drawText. That interprets all the text codes in your text.
I think you probably want the drawTextEx function, rather than drawText. That interprets all the text codes in your text.

True, that would also be a solution for the color problem. But unfortunately not for the new line problem.
At least, new line is not an option in message box text codes.

//Edit: Ok nevermind, I guess \n is included as a new line command in textEx. Thanks!
//Edit2: new line code does NOT work, only when entering it in the developer console while the game is playing. But not ingame unfortunately.
just tested, it works without a plugin, you can just use \c[12] text here \c[0] (enter)
for a new \c[14]line here\c[0].

which is possible by default. no \n is need or <br> unless you have a plugin that allows you too?
Handling of newlines is included in drawTextEx. If you're calling it from a script and the string contains a newline already, then drawTextEx will go to a new line when it gets there. However, if you have text that contains the \n escape sequence rather than an actual newline, it will not work, as that \ will be removed by the escape parsing code and then you're left with just n which is obviously not a newline.
Im calling the text from the item description, which only allows 2 lines in the database. It would be a bit difficult to have to save the text for item description anywhere else than in the box provided by MV.

I wrote a function now, that would take care of that.
for those who are interested:

JavaScript:
Window_MenuInventoryKeyList.prototype.updateDesc = function(item, x, y, lineSpace) {
    item ? text = item.description : text = "";
    var menuInvent = SceneManager._scene._menuInventory;
    var newLines = text.split("/n");
    var n = lineSpace || 20;
    menuInvent.contents.clear();
    menuInvent.refresh();
    menuInvent.resetTextColor();
    for (i = 0; i < newLines.length; i++) {
        menuInvent.drawTextEx(newLines[i], x, y);
        y += n;
    }
};
Explanation: while \n represents a new line, if you enter that into any text-entry field in the editor it'll be stored as two characters: backslash (encoded as \\) and n. 👋

That said, if you were to have your code split on "\\n" instead, you'd encounter conflicts with the pre-existing escape sequence: \N[x] = name of actor ID x. So alternatives like /n or <br> tend to get used instead. 🙏
Let me rewrite this cleaner without my own game stuff in it:

JavaScript:
Window_AnyWindow.prototype.drawTextWithNewLines = function(item, x, y, lineSpace) {
    item ? text = item.description : text = "";
    var newLines = text.split("/n"); //Or any of your own split code
    var n = lineSpace || 20;
    for (i = 0; i < newLines.length; i++) {
        this.drawTextEx(newLines[i], x, y);
        y += n;
    }
};
Since you're reading an item's description, I'm pretty sure you don't need a loop or even a new function for this. Just call:

JavaScript:
this.drawTextEx(item.description || "");

The drawTextEx function already handles newlines for you, as long as they're real newlines. If you're trying to make the item description more than two lines by adding a special code, then you can use the following call instead:

JavaScript:
var description = item.description || "";
description = description.replace(/<br>/g, '\n');
this.drawTextEx(description);

Basically, replace your special code with actual newlines, then call drawTextEx. If you want your special code to be /n, then replace /<br>/g with /\/n/g.
Since you're reading an item's description, I'm pretty sure you don't need a loop or even a new function for this. Just call:

JavaScript:
this.drawTextEx(item.description || "");

The drawTextEx function already handles newlines for you, as long as they're real newlines. If you're trying to make the item description more than two lines by adding a special code, then you can use the following call instead:

JavaScript:
var description = item.description || "";
description = description.replace(/<br>/g, '\n');
this.drawTextEx(description);

Basically, replace your special code with actual newlines, then call drawTextEx. If you want your special code to be /n, then replace /<br>/g with /\/n/g.

Ok, so I tried your method, but it didn't work.

JavaScript:
Window_MenuInventoryKeyList.prototype.updateDesc = function(item, x, y) {
    var menuInvent = SceneManager._scene._menuInventory;
    menuInvent.contents.clear();
    menuInvent.refresh();
    menuInvent.resetTextColor();
    var description = item.description || "";
    description = description.replace(/<br>/g, '/\/n/g');
    menuInvent.drawTextEx(description, x, y);
};

Note that I also tried using "\n" instead of my "/n" and no difference unfortunately.

This is how it should look like (with my loop):
desciption.JPG


This is how it looks like with your method:
desciption2.JPG


This is the Text insert into the description box in MV:

"\C[2]LEVEL 3 KEYCARD\C[0]/n/nA \C[1]level 3 access\C[0] keycard for the \C[1]science labs\C[0] on the \C[1]UEG Phobos\C[0], which are off-limits for any
/nnon-essential personell./n/nBe advised - Entering without proper authorization or disguise might raise unwanted attention."


Remember, the description box only allows me to put in 2 lines of text, no line breaks.

This shouldn't sound demeaning or anything. I would love to not have to use a loop and solve all this in a few simple lines, but either I'm too stupid to make this work or RPG Maker is interfering somewhere in the process.
I believe you misapplied this line in my previous post:
If you want your special code to be /n, then replace /<br>/g with /\/n/g.

Your code is replacing <br> with /n instead of /n with \n.
I believe you misapplied this line in my previous post:


Your code is replacing <br> with /n instead of /n with \n.

If this is what you meant:
JavaScript:
description = description.replace(/\/n/g, '/n');

I get the same results as posted above.
Almost - you want '\n', not '/n'.
Almost - you want '\n', not '/n'.

Ohhhh, ok finally it works, haha. Thanks for you patience!

Original thread: https://forums.rpgmakerweb.com/threads/how-do-i-draw-a-text-in-costum-menu-with-color-change-and-new-line.123895/