how to store an escape character in a variable string?

Status
Not open for further replies.

sutorumie

I'm a whimsical girl.
Veteran
Joined
Apr 26, 2014
Messages
30
Reaction score
1
First Language
English
Primarily Uses
RMMV
I'm attempting to make random NPC dialogue by setting up a variable to store the dialogue into, then defining the variable as a text string which is randomly selected via condition branch / rng variable. However, when I want to make the NPC say the player character's name, it instead displays it as just "N[1]". I tried using \\N[1] in the string instead of \N[1] but this just makes "\N[1]" display in the text box. \n works just fine for linebreaks though, which I found out by accident lol

Is there a way around this? \\\N[1] doesn't work either.




I wasn't able to find anything about this by googling or searching these forums, maybe I'm using the wrong terms (or maybe it's my ADD making it hard to read 100% of the things I see) but I can't seem to find anything even remotely close to what I'm looking for
 

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
5,594
Reaction score
6,525
First Language
Indonesian
Primarily Uses
RMVXA
First, your text style of using red is not necessary, it hurts in dark mode. Besides, not sure if you're even allowed to use red/blue text color in your text bcz, well, rules.

Second, try to add double slash instead. Like \\N[12].
 

gstv87

Veteran
Veteran
Joined
Oct 20, 2015
Messages
2,248
Reaction score
1,252
First Language
Spanish
Primarily Uses
RMVXA
I believe the reason why it's not working, is because when you order a display of \v[X], the result of \v[X] (actually a string with an escape character in it), is not further processed as *a string with an escape character in it*
it is presented as "a final result contained in this variable". (the final result being, a string, with an escape character, which should be processed, but isn't)
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,125
Reaction score
10,639
First Language
Czech
Primarily Uses
RMMV
I don't think you can put \n[1] inside a variable and display it like that, since message window doesn't allow compound tags (meaning you cannot have a tag inside a tag). Under normal circumstances \\N[1] (execution via code for example) would have worked, but not inside a tag. The reason why \n works as a new line is simply it being a thing of Javascript.

Btw. @TheoAllen red and blue are alright in the OP. In replies they would not be alright. Nevertheless, I agree that this kind of red is too dark.
 

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
5,594
Reaction score
6,525
First Language
Indonesian
Primarily Uses
RMVXA
@Poryg ya know, it's okay to use it for OP formatting like a game thread. But I'm afraid this kind of stylizing will be carried into replies for a sake of being stylish (and she did). I know I did too in the long past.

As for being an actual topic, those two explanations make sense, and I missed that in fact, you did it urself and didn't work, which again I missed to read it because of the color.
 

gstv87

Veteran
Veteran
Joined
Oct 20, 2015
Messages
2,248
Reaction score
1,252
First Language
Spanish
Primarily Uses
RMVXA
I don't think you can put \n[1] inside a variable and display it like that, since message window doesn't allow compound tags (meaning you cannot have a tag inside a tag)
you can't, because the process delivers what's in that variable and exits without double-checking, but you could, if you took the result and feed it back to the same process in order to catch that nested tag.

all I have is Ace at hand, this is a shot in the dark, but hopefully you'll get the idea.
Code:
def convert_escape_characters(text)
    result = text.to_s.clone
    result.gsub!(/\\/)            { "\e" }
    result.gsub!(/\e\e/)          { "\\" }
    result.gsub!(/\eV\[(\d+)\]/i) { $game_variables[$1.to_i] }
    result.gsub!(/\eN\[(\d+)\]/i) { actor_name($1.to_i) }
    result.gsub!(/\eP\[(\d+)\]/i) { party_member_name($1.to_i) }
    result.gsub!(/\eG/i)          { Vocab::currency_unit }
    result
  end
Code:
    result.gsub!(/\eV\[(\d+)\]/i) { $game_variables[$1.to_i] }

   result.gsub!(/\eV\[(\d+)\]/i) { convert_escape_characters($1)}
just as \n triggers a call to actor_name(result_of_operation), set \v to trigger a convert_escape_characters(result_of_operation), with "convert_escape_characters()" being in fact "ourselves", from the method's own point of view.
in essence, a feedback.
 

sutorumie

I'm a whimsical girl.
Veteran
Joined
Apr 26, 2014
Messages
30
Reaction score
1
First Language
English
Primarily Uses
RMMV
@gstv87 So I went through rpg_windows.js looking for something similar to those codes you posted, and I found the section on escape codes, but it wasn't quite formatted similarly enough for me to have any idea what to do with it. I started looking at the codes below to see if maybe there was something defined there, and I found this:

Code:
case '\x1b':

        this.processEscapeCharacter(this.obtainEscapeCode(textState), textState);
        break;
So I thought to myself... maybe I can use that?



Annnnd, voila!



Perfect! Thanks for pointing me in the right direction c:
 

mlogan

Global Moderators
Global Mod
Joined
Mar 18, 2012
Messages
15,354
Reaction score
8,536
First Language
English
Primarily Uses
RMMV

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

 
Status
Not open for further replies.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Are we allowed to post about non-RPG Maker games?
I should realize that error was produced by a outdated version of MZ so that's why it pop up like that
Ami
i can't wait to drink some ice after struggling with my illness in 9 days. 9 days is really bad for me,i can't focus with my shop and even can't do something with my project
How many hours have you got in mz so far?

A bit of a "sparkle" update to the lower portion of the world map. :LZSexcite:

Forum statistics

Threads
105,883
Messages
1,017,236
Members
137,608
Latest member
Arm9
Top