How to "Show Text" in a message window using RGSS?

*Edit* I'm using RPG Maker XP!

I'm working on an introduction script for my game, and I need to be able to mimic the effect of the Event Command "Show Text" - meaning I want to display a series of messages that will introduce my game. Could somebody explain to me the best way to accomplish this?
I'm not quite sure what you're trying to get that you can't do with regular messages. Let's say you're in a scene outside Scene_Map, meaning there's no message window present, you could still take a look at how it's initialized and set up in that scene (along with Spriteset_Map maybe... not sure, but probably not) and mimic that setup in your custom introductional scene, being able to create a new message the regular (scripted) way.

That is pretty in-general, however you chose to keep your RPG Maker version a secret, which is why I can't help you any further here :p
Thanks BlueScope for your reply, sorry I forgot to mention I'm using RMXP. Let me be more specific about my script as well: As you suggested, I am creating a new scene called Scene_Intro. (Of course I could do everything I want to accomplish easily with events, but this is a learning project for me as I am trying to learn RGSS.) My script will work similar to the way the title screen works by displaying a background image, but without the command window. It will instead, display a message window to introduce the game! I would like to accomplish this completely event free. Do I need to create another class, something like class Intro_Window and call it from my Scene_Intro? Or is there another way of doing it? Preferably, I would like the intro text to be easily customizable by different users.
You can't use Window_Message, the window used to display text in the game.
It uses variables which will be defined only later, when the game starts.
make your own simple window, something like:
  1. class Mywindow < Window_Selectable
  2.   def initialize
  3.       super(80, 304, 480, 160)
  4.       self.contents = Bitmap.new(width - 32, height - 32)
  5.   end
  6.  
  7.   def show(text)
  8.     @text = text
  9.   end
  10.  
  11.   def update
  12.     self.contents.clear
  13.     self.contents.draw_text(x, y, width, height, @text, align)
  14.     # if you wish to mimic the default message :
  15.     # self.contents.draw_text(0, 32* line, width, 32, @text, 0)
  16.   end
  17.  
  18. end
Expand to see the code.


Your scene should create and update the window. Its update method should check if Enter was pressed, and if so show the next message.
  1. class Scene_Intro
  2.   def main
  3.      @message_window = Mywindow.new
  4.      # show title picture
  5.      @sprite = Sprite.new
  6.      @sprite.bitmap = RPG::Cache.title($data_system.title_name)
  7.       # you probably want to store all the text in an array.
  8.      @array = [ "message", "second message" ..]
  9.      @i = 0
  10.      loop do
  11.        # Update game screen
  12.        Graphics.update
  13.        # Update input information
  14.        Input.update
  15.        # Frame update
  16.        update
  17.        # Abort loop if screen is changed
  18.        if $scene != self
  19.          break
  20.        end
  21.     end
  22.     @message_window.dispose
  23.     @sprite.bitmap.dispose
  24.     @sprite.dispose
  25.   end
  26.  
  27.   def update
  28.     # if player hits Enter, Space or X
  29.     if Input.trigger?(Input::C)
  30.       @i += 1
  31.       # if done showing all messages
  32.       if (@i == @array.size)  
  33.         # exit this scene and go to title screen
  34.         $scene = Scene_Title.new
  35.       else
  36.         next_message = @array[@i]  
  37.         @message_window.show(next_message)
  38.       end
  39.     end
  40.     @message_window.update
  41.   end
  42.  
  43. end
Expand to see the code.
I don'T see why you wouldn't be able to set these variables yourself, temporarily... creating a second window to mimic one that's already accessible seems weird to me, especially since people are likely to use CMS' and therefore might want to keep a distinct style to their game, not necessarily achieveable your way (even the default downpoint animation, for example, won't be working this way).
But yeah, other than that, it's a completely fine and clean way to do this... if it's not about perfect exactness.
Yeah, it's possible to use Window_Message, if you first create $game_temp, $game_variables and $game_actors, and set $game_temp.message_text to the next message.
It just seems like an overkill for a simple task of showing text and the title picture.
It's unlikely anyone will need a number input, a game variable or actor's name during the intro. Show choices, however, may come in handy- if you want to select a playable character, for example.
Do you know how to add the down animation to a window?
Well, while I could draw the animation manually with ease, I don't know if there's a method, flar or whatever you can assign to a window to get it. I'm pretty sure it's in Window_Message, though, if anywhere in the non-hidden scripts.
And yeah, I think setting all that (which you set later anyway, so it's not actually 'more' you do) isn't more overkilling than creating an entirely new window, and after all, you don't have to mess with anything at all either way (like I said: Custom message system that might offer a bazilion functions, or the integration of my Multiple Language script that you basically would have to recreate). All in all, I doubt having the same thing used for the same occassion can be worse than having a cloned attempt...
Thank you both for your replies (and your different point of views)! Your explanations have helped me to understand windows a lot better. I have only been working with RGSS for a few weeks now and this will be my first time creating windows.

silver wind wrote:
Do you know how to add the down animation to a window?


I do not know how to add the down animation to a window yet, which is actually another question I would have asked. I would like to create a custom down animation that displays after the final word in the window, rather than at the bottom of the window.

BlueScope wrote:
creating a second window to mimic one that's already accessible seems weird to me, especially since people are likely to use CMS' and therefore might want to keep a distinct style to their game, not necessarily achieveable your way (even the default downpoint animation, for example, won't be working this way).


When you have time, could you explain to me how you might go about this your way? Your argument on keeping a distinct style throughout the game is quite valid. In my intro, it may be optimal for the window to match the rest of the game automatically. How could I ensure that my intro window will work with someone's CMS? (Actually, I'm sure I will be writing my own CMS for this project eventually.)

Here's a bit more information about what I would like to accomplish in the Intro: At some point, the player will choose between two playable characters. Then the player will be able to name the hero. Other than that, it will just be text for the player to read through.

Thanks again for all your help!
XeroVolume wrote:
At some point, the player will choose between two playable characters. Then the player will be able to name the hero. Other than that, it will just be text for the player to read through.

Thanks again for all your help!

In that case, you're better with BlueScope's way.
All you'll have to change in the script I posted earlier is:

1. @message_window = Mywindow.new

instead, use:
$game_temp = Game_Temp.new
$game_actors = Game_Actors.new
$game_variables = Game_Variables.new
@message_window = Window_Message.new

2. @message_window.show(next_message)
instead use:
$game_temp.message_text = next_message
silver wind, I am getting a no method error with your script:

undefined method 'show' for #<Window_Message:0x4b37578>

any ideas?
you didn't replace the @message_window.show(next_message) line, like I said :p
oh WOW I can't believe I missed that! I thought maybe there was some hidden method called show or something but I couldn't figure it out... Anyway there are a few bugs I noticed, except this time I was able to figure them out. 😀 Here's your script again, slightly tweaked so that it works the way you had in mind.

  1. class Scene_Intro
  2.   def main
  3.      @message_window = Window_Message.new
  4.      # show title picture
  5.      @sprite = Sprite.new
  6.      @sprite.bitmap = RPG::Cache.title($data_system.title_name)
  7.       # you probably want to store all the text in an array.
  8.      @array = [ "message", "second message" ]
  9.      @i = 0
  10.      # Transition run
  11.      Graphics.transition
  12.      loop do
  13.        # Update game screen
  14.        Graphics.update
  15.        # Update input information
  16.        Input.update
  17.        # Frame update
  18.        update
  19.        # Abort loop if screen is changed
  20.        if $scene != self
  21.          break
  22.        end
  23.     end
  24.     @message_window.dispose
  25.     @sprite.bitmap.dispose
  26.     @sprite.dispose
  27.   end
  28.  
  29.   def update
  30.     next_message = @array[@i]
  31.     $game_temp.message_text = (next_message)
  32.     # if player hits Enter, Space or X
  33.     if Input.trigger?(Input::C)
  34.       @i += 1
  35.       # if done showing all messages
  36.       if (@i == @array.size)  
  37.         # exit this scene and go to title screen
  38.         $scene = Scene_Title.new
  39.       end
  40.     end
  41.     @message_window.update
  42.   end
  43.  
  44. end
Expand to see the code.


First, you forgot the Graphics.transition before the loop. Next, it wasn't displaying the messages correctly because it was first checking if the player pressed C before it would set $game_temp.message_text = (message_next) and therefore @i was set to 1 before it even displayed the first window. I moved next_message = @array[@i] and $game_temp.message_text = (next_message) outside of the if statement and now everything works according to plan!

Oh yeah I almost forgot: I didn't need to create $game_temp, $game_variables and $game_actors because my intro script will come just after the title screen, (and only if the player selects new game) and the title screen sets those variables for me.

I never could have done this without you silver wind! Thank you so much! So... any tips on creating that custom down animation?
You're welcome, I'm sure you could, though :)

The help file says the down animation is controlled by:
@pause = true # show down animation
@pause = false # hide animation
The actual method to show the animation is in the hidden class Window. In other words, I don't have a clue. o.o
I've come across another bug that I'm having trouble correcting. It is caused by the following line:

  1. # if Input.trigger?(Input::C)
  2. #       @i += 1
Expand to see the code.


Say someone is trying to scroll through the intro messages very fast and they just keep pressing C (Everyone does this). Well by the time the first message is displayed, they could have pressed C five (or more) times, which would set @i to 5, thus instead of displaying the remaining messages in order, it would skip to the 5th message in the array. (well, fourth when you include the zero)

I hope I've described this bug accurately enough... Any ideas on how to fix this?

I've been looking through all the window classes but I can't find how the default scripts handle this issue. How can I correct the script so that it adds 1 to @i when C is pressed but only after the current message in the array is displayed? I know some CMS' have one letter at a time features which obviously have to deal with this problem in some way. I guess I'll have a look at some of them and see if I can find something useful.
Ok here's what I have now. It seems to be an improvement, but still not perfect. I need some help guys!

  1. class Scene_Intro
  2.   def main
  3.      # Create message window
  4.      @message_window = Window_Message.new
  5.      # Create background image
  6.      @sprite = Sprite.new
  7.      @sprite.bitmap = RPG::Cache.title($data_system.title_name)
  8.       # Array for storing intro messages
  9.      @array = [ "message", "second message", "third message" ]
  10.      # The index of the message being displayed
  11.      @i = 0
  12.      # Initialize the first message
  13.      $game_temp.message_text = @array[@i]
  14.      # Transition run
  15.      Graphics.transition
  16.      loop do
  17.        # Update game screen
  18.        Graphics.update
  19.        # Update input information
  20.        Input.update
  21.        # Frame update
  22.        update
  23.        # Abort loop if screen is changed
  24.        if $scene != self
  25.          break
  26.        end
  27.      end
  28.     # Frreeze the Graphics
  29.     Graphics.freeze
  30.     # Dispose the window(s) & sprite(s)
  31.     @message_window.dispose
  32.     @sprite.bitmap.dispose
  33.     @sprite.dispose
  34.   end
  35.  
  36.   def update
  37.     # Update the message window
  38.     @message_window.update
  39.     # If showing message window
  40.     if $game_temp.message_window_showing
  41.       return
  42.     end
  43.     @i += 1
  44.     # If finished showing all messages in array
  45.     if (@i == @array.size)  
  46.       # Switch to map screen
  47.       return $scene = Scene_Map.new
  48.     end
  49.     # Otherwise, set the message_text to the next item in the array
  50.     $game_temp.message_text = @array[@i]
  51.   end
  52. end
Expand to see the code.


Using $game_temp.message_window_showing solves my original problem, but it also creates a new one. Now the message window disappears for a split second in between each message!

The player presses C, the message window disappears, @i is updated, message_text is set to the next item in the array, and then a new message window displays showing the next message in order.

I hate to be a nuisance but this just doesn't look right. When you "Show Text" from an Event Command, the message window does not disappear between each message.

What's the secret?
Hmm. I don't know how it's done automatically.
This edit to window_message will stop it from 'blinking', just add this line to intro_scene: @message_window.dont_fade_out
  1. class Window_Message < Window_Selectable
  2.  
  3.   attr_accessor  :dont_fade_out
  4.  
  5.   def dont_fade_out
  6.     @dont_fade = true
  7.   end
  8.  
  9.   def update
  10.     super
  11.     # If fade in
  12.     if @fade_in
  13.       self.contents_opacity += 24
  14.       if @input_number_window != nil
  15.         @input_number_window.contents_opacity += 24
  16.       end
  17.       if self.contents_opacity == 255
  18.         @fade_in = false
  19.       end
  20.       return
  21.     end
  22.     # If inputting number
  23.     if @input_number_window != nil
  24.       @input_number_window.update
  25.       # Confirm
  26.       if Input.trigger?(Input::C)
  27.         $game_system.se_play($data_system.decision_se)
  28.         $game_variables[$game_temp.num_input_variable_id] =
  29.           @input_number_window.number
  30.         $game_map.need_refresh = true
  31.         # Dispose of number input window
  32.         @input_number_window.dispose
  33.         @input_number_window = nil
  34.         terminate_message
  35.       end
  36.       return
  37.     end
  38.     # If message is being displayed
  39.     if @contents_showing
  40.       # If choice isn't being displayed, show pause sign
  41.       if $game_temp.choice_max == 0
  42.         self.pause = true
  43.       end
  44.       # Cancel
  45.       if Input.trigger?(Input::B)
  46.         if $game_temp.choice_max > 0 and $game_temp.choice_cancel_type > 0
  47.           $game_system.se_play($data_system.cancel_se)
  48.           $game_temp.choice_proc.call($game_temp.choice_cancel_type - 1)
  49.           terminate_message
  50.         end
  51.       end
  52.       # Confirm
  53.       if Input.trigger?(Input::C)
  54.         if $game_temp.choice_max > 0
  55.           $game_system.se_play($data_system.decision_se)
  56.           $game_temp.choice_proc.call(self.index)
  57.         end
  58.         terminate_message
  59.       end
  60.       return
  61.     end
  62.     # If display wait message or choice exists when not fading out
  63.     if @fade_out == false and $game_temp.message_text != nil
  64.       @contents_showing = true
  65.       $game_temp.message_window_showing = true
  66.       reset_window
  67.       refresh
  68.       Graphics.frame_reset
  69.       self.visible = true
  70.       self.contents_opacity = 0
  71.       if @input_number_window != nil
  72.         @input_number_window.contents_opacity = 0
  73.       end
  74.       @fade_in = true
  75.       return
  76.     end
  77.     # If message which should be displayed is not shown, but window is visible
  78.     if self.visible
  79.       # --------------- my edit ----------------- #
  80.       if @dont_fade
  81.         @fade_out = false
  82.         $game_temp.message_window_showing = false
  83.         return
  84.       end
  85.       # --------------- my edit ----------------- #
  86.       @fade_out = true
  87.       self.opacity -= 48
  88.       if self.opacity == 0
  89.         self.visible = false
  90.         @fade_out = false
  91.         $game_temp.message_window_showing = false
  92.       end
  93.       return
  94.     end
  95.   end
  96.  
  97. end
Expand to see the code.

lines 86-92 are causing the window to fade out and disappear. calling @message_window.dont_fade_out will stop it from doing that.
Note how @dont_fade evaluates to false by default, as it doesn't exist until you call the dont_fade_out method. In other words, this will have no effect on in-game messages, as my if condition(line 80) will always be false for them.
Thanks silver wind! This is great! Now it works exactly like I've been wanting. If we only knew how the "Show Text" Event Command does it, then we wouldn't have to edit Window_Message!

XeroVolume (Yes I'm quoting myself!) wrote:
When you "Show Text" from an Event Command, the message window does not disappear between each message.
silver wind wrote:
Hmm. I don't know how it's done automatically.

I am very interested in finding out how this is done without having to edit Window_Message! Does anybody have any idea?

Either way, thank you so much silver wind! You've been a great help with not only my script, but also my understanding of RGSS!
Glad I could help :)
I'm also curious how it's done normally. I guess it's inside Interpreter's command 101 (show text), as this is the class handling event commands and it can check if the next command is another show-text.
You're exactly right silver wind. The "secret" is in the following lines inside Interpreter's command_101 method:

# Set message end waiting flag and callback
@message_waiting = true
$game_temp.message_proc = Proc.new { @message_waiting = false }

The help file doesn't do much to explain the Proc function, and all I know is that the "Show Text" Event Command uses it so if I want to mimic that command, I need to use it as well. It took a lot of copying and pasting of random blocks of suspicious code to figure this out, not to mention all the help from my fellow scripters! (Thank you bluescope, silver wind, and Night_Rider for all your help!)

And here is the functional core of my Intro Script:

  1. #==============================================================================
  2. # ** Scene_Intro
  3. #------------------------------------------------------------------------------
  4. #  This class performs intro screen processing.
  5. #==============================================================================
  6.  
  7. class Scene_Intro
  8.   #--------------------------------------------------------------------------
  9.   # * Main Processing
  10.   #--------------------------------------------------------------------------
  11.   def main
  12.      # Create message window
  13.      @message_window = Window_Message.new
  14.      # Create background image
  15.      @sprite = Sprite.new
  16.      @sprite.bitmap = RPG::Cache.title($data_system.title_name)
  17.      # Array for storing intro messages
  18.      @array = [ "first message", "second message", "third message" ]
  19.      # The index of the message being displayed
  20.      @i = -1
  21.      # Transition run
  22.      Graphics.transition
  23.      loop do
  24.        # Update game screen
  25.        Graphics.update
  26.        # Update input information
  27.        Input.update
  28.        # Frame update
  29.        update
  30.        # Abort loop if screen is changed
  31.        if $scene != self
  32.          break
  33.        end
  34.      end
  35.     # Frreeze the Graphics
  36.     Graphics.freeze
  37.     # Dispose of message window
  38.     @message_window.dispose
  39.     # Dispose of title image
  40.     @sprite.bitmap.dispose
  41.     @sprite.dispose
  42.     # If switching to map screen
  43.     if $scene.is_a?(Scene_Map)
  44.       # Fade out screen
  45.       Graphics.transition
  46.       Graphics.freeze
  47.     end
  48.   end
  49.   #--------------------------------------------------------------------------
  50.   # * Frame Update
  51.   #--------------------------------------------------------------------------
  52.   def update
  53.     # If the message_text is empty
  54.     if $game_temp.message_text == nil
  55.       @i += 1
  56.       # If finished showing all messages in array
  57.       if (@i == @array.size)  
  58.         # Switch to map screen
  59.         return $scene = Scene_Map.new
  60.       end
  61.       # Set message end waiting flag and callback
  62.       @message_waiting = true
  63.       $game_temp.message_proc = Proc.new { @message_waiting = false }
  64.       # Set the message text to the next item in the array
  65.       $game_temp.message_text = @array[@i]
  66.     end
  67.     # Update the message_window
  68.     @message_window.update
  69.   end
  70. end
Expand to see the code.


This way, no editing of class Window_Message is needed!

Whew, now I can finally get back to work on the rest of the Intro Scene! :thumb:

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=71196