how to store an escape character in a variable string?

Discussion in 'RPG Maker MV' started by sutorumie, Nov 7, 2018.

Thread Status:
Not open for further replies.
  1. sutorumie

    sutorumie I'm a whimsical girl. Veteran

    Messages:
    30
    Likes Received:
    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.


    [​IMG]

    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
     
    #1
  2. TheoAllen

    TheoAllen Self-proclaimed jack of all trades Veteran

    Messages:
    3,867
    Likes Received:
    4,200
    Location:
    Riftverse
    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].
     
    #2
  3. gstv87

    gstv87 Veteran Veteran

    Messages:
    1,543
    Likes Received:
    596
    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)
     
    #3
  4. Poryg

    Poryg Pixie of the Emvee kingdom, Ham of a Hamster Veteran

    Messages:
    3,432
    Likes Received:
    8,409
    Location:
    Czech Republic
    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.
     
    #4
  5. TheoAllen

    TheoAllen Self-proclaimed jack of all trades Veteran

    Messages:
    3,867
    Likes Received:
    4,200
    Location:
    Riftverse
    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.
     
    #5
  6. gstv87

    gstv87 Veteran Veteran

    Messages:
    1,543
    Likes Received:
    596
    First Language:
    Spanish
    Primarily Uses:
    RMVXA
    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.
     
    #6
    sutorumie likes this.
  7. sutorumie

    sutorumie I'm a whimsical girl. Veteran

    Messages:
    30
    Likes Received:
    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?

    [​IMG]

    Annnnd, voila!

    [​IMG]

    Perfect! Thanks for pointing me in the right direction c:
     
    #7
  8. mlogan

    mlogan Global Moderators Global Mod

    Messages:
    13,333
    Likes Received:
    7,375
    Location:
    Texas
    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.

     
    #8
Thread Status:
Not open for further replies.

Share This Page