how to store an escape character in a variable string?

● ARCHIVED · READ-ONLY
Started by sutorumie 8 posts View original ↗
  1. 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.


    tumblr_pht6a5Mws61qi7tzho1_r1_1280.png

    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
  2. 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].
  3. 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)
  4. 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.
  5. @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.
  6. Poryg said:
    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.
  7. @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?

    tumblr_pht6a5Mws61qi7tzho1_r2_1280.png

    Annnnd, voila!

    tumblr_pht6a5Mws61qi7tzho2_r2_1280.png

    Perfect! Thanks for pointing me in the right direction c:
  8. 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.