[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,055
Reaction score
7,143
First Language
Indonesian
Primarily Uses
RMVXA
Use double \\C[0]
Or \eC[0]
 

Roninator2

Gamer
Veteran
Joined
May 22, 2016
Messages
2,908
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,055
Reaction score
7,143
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,222
Reaction score
14,250
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

I once thought about a boss gauntled game. I actually did it.
Stream will be live shortly with some Gex 3! Feel free to drop by!
Snippet from a game I'm working on. Not much happening here. Mostly look at atmosphere. May upload a longer version. Still need to make up some enemy arts.
Been slightly struggling with developing the latest chapter, I think I will downscale my ambitions and make it more linear.

Forum statistics

Threads
109,056
Messages
1,041,679
Members
141,541
Latest member
emythystvial
Top