Replace Method Issue

I have been editing the default Window_Status code, removing the actor parameters and equipment to open up an larger area for the actor profile. The stored profile text is passed through drawTextEx which uses the convertEscapeCharacters function. Now, convertEscapeCharacters should convert the new line escape codes I placed into the text, but it doesn't.


Here is the simple, two line dummy text which is stored in the profile :


Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n Quisque arcu quam, convallis rutrum neque id, cursus est.




[Console]


> typeof $gameActors.actor(1)._profile;
< "string"


Ok.


> $gameActors.actor(1)._profile;
< "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n Quisque arcu quam, convallis rutrum neque id, cursus est."


Ok.


> Window_Base.prototype.convertEscapeCharacters($gameActors.actor(1)._profile);
< "Lorem ipsum dolor sit amet, consectetur adipiscing elit.n Quisque arcu quam, convallis rutrum neque id, cursus est."


Wait, what? The function should be replacing '\n' with '\x1bn' which then is converted into a new line.


Window_Base.prototype.convertEscapeCharacters = function(text) {
//
// Replacement
text = text.replace(/\\/g, '\x1b');
//
//
text = text.replace(/\x1b\x1b/g, '\\');
text = text.replace(/\x1bV\[(\d+)\]/gi, function() {
return $gameVariables.value(parseInt(arguments[1]));
}.bind(this));
text = text.replace(/\x1bV\[(\d+)\]/gi, function() {
return $gameVariables.value(parseInt(arguments[1]));
}.bind(this));
text = text.replace(/\x1bN\[(\d+)\]/gi, function() {
return this.actorName(parseInt(arguments[1]));
}.bind(this));
text = text.replace(/\x1bP\[(\d+)\]/gi, function() {
return this.partyMemberName(parseInt(arguments[1]));
}.bind(this));
text = text.replace(/\x1bG/gi, TextManager.currencyUnit);
return text;
};


regex-matches.png






Why do you do this, function?
It looks like the actors json is saved by converting the \n to \\n in the profile descriptions.
It looks like the actors json is saved by converting the \n to \\n in the profile descriptions.



Mmhmm ... but other escape codes are converted in the same way, yet those seem to work just fine.


\I[5]Suspendisse \C[5]egestas, velit sed\C[0] accumsan tincidunt, orci\nleo posuere ipsum, nec tristique tortor arcu eu ligula.


Each one works as it should except for the new line code.


EDIT: Ah, I guess the function is not looking for '\n' in textual form, but the actual ANSI newline character. Blah. I guess aliasing the convertEscapeCharacters to slip in a replace for '\n' is best, then. Brain is frazzled.

Original thread: https://forums.rpgmakerweb.com/threads/replace-method-issue.65976/