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

Status
Not open for further replies.

ZachyTemp

[Insert Title]
Veteran
Joined
Apr 20, 2020
Messages
31
Reaction score
14
First Language
Spanish
Primarily Uses
RMVXA
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 ;(
 

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
6,048
Reaction score
7,135
First Language
Indonesian
Primarily Uses
RMVXA
Use double \\C[0]
Or \eC[0]
 

Roninator2

Gamer
Veteran
Joined
May 22, 2016
Messages
2,893
Reaction score
642
First Language
English
Primarily Uses
RMVXA
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
 

ZachyTemp

[Insert Title]
Veteran
Joined
Apr 20, 2020
Messages
31
Reaction score
14
First Language
Spanish
Primarily Uses
RMVXA
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 ^^
 

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
6,048
Reaction score
7,135
First Language
Indonesian
Primarily Uses
RMVXA
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
 

ZachyTemp

[Insert Title]
Veteran
Joined
Apr 20, 2020
Messages
31
Reaction score
14
First Language
Spanish
Primarily Uses
RMVXA
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!
 

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
41,150
Reaction score
14,206
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.

Latest Threads

Latest Profile Posts

elex 50s face.png

Experimenting with an old 50's style face set. I have done about a dozen variations of face sets for my characters, but am never happy with the results for very long. Different attempts. Second one is the same character as the first image. The third is Ivan, another character entirely.
treele.jpg
A them/they in a forest... a still for the game I'm working on.
Making a blue-magic-heavy game is very fun but there's a lot of extra hassle as well. Balancing skills for both enemy and player usage isn't easy.
BTW everyone on staff who made the forum jump, thank-you! This time I am not panicked and lost all rounds.
I'm not searching for bugs, just pleasant surprises, for now on ^^

Forum statistics

Threads
108,838
Messages
1,039,950
Members
141,302
Latest member
Dolos
Top