[VX Ace] How to use escape characters on a "$game_message.add" call?

Hello,

I've been struggling with this lately, as I noticed the Game_Message class is unable to process escape characters. I know this is done by the Window_Message instead, but I don't know how to use this on a script call.

When I try to use any escape character it'll return a syntax error.

This is the method I'm using right now:
Ruby:
# Draw Message
  def message(string)

    $game_map.screen.pictures[@z-1].show("Battle/Message",0,-280,0,100,100,100,0)
    $game_map.screen.pictures[@z-1].move(0,0,0,100,100,100,0,10)
    
    xy = [$message.x,$message.y]
    
    $message.x = 0
    $message.y = 412
    $game_message.background = 2
    $game_message.add("\C[0]#{string}\.\.\.\^") # --> Invalid escape character syntax
    Fiber.yield while $game_message.busy?
      
    $message.x = xy[0]
    $message.y = xy[1]
    
  end # Method

Sorry if this is kind of a stupid question, but I don't really know a lot about coding ;(
Use double \\C[0]
Or \eC[0]
try putting that into a local variable and then add it to the message
text = "\C[0]#{string}\.\.\.\^"
$game_message.add(text)

The game message may not able to process the interpolation of the string insertion, but using a variable will correct this.

Or what TheoAllen said
try putting that into a local variable and then add it to the message
text = "\C[0]#{string}\.\.\.\^"
$game_message.add(text)

The game message may not able to process the interpolation of the string insertion, but using a variable will correct this.

Or what TheoAllen said

It does support string interpolation, as I tried multiple times with different combinations and the only issue was the escape character. I appreciate the idea though!

Use double \\C[0]
Or \eC[0]

Works like a charm, thanks a lot! I guess using double \\ makes sense, since that returns a "\" character and leaves the escape character processing to the Window_Message class.

But what does \e mean? If it's not too much trouble to explain ^^
But what does \e mean? If it's not too much trouble to explain ^^
the window will convert \\ character to \e before processing as an escape command. Putting \e will also work, however, I don't remember the exact conversion. It might be \\e or something. I can not open RM at the moment.

You can try to look at the method in the Window_Base --> convert_escape_character
the window will convert \\ character to \e before processing as an escape command. Putting \e will also work, however, I don't remember the exact conversion. It might be \\e or something. I can not open RM at the moment.

You can try to look at the method in the Window_Base --> convert_escape_character

Ah, yes.
Ruby:
result.gsub!(/\\/)            { "\e" }
result.gsub!(/\e\e/)          { "\\" }

I believe this is it. Thanks again!
Thread closed

Original thread: https://forums.rpgmakerweb.com/threads/vx-ace-how-to-use-escape-characters-on-a-game_message-add-call.132465/