Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

How do I implement Letter by letter and Message delay in my Message Script?

Good day everybody!

I've come today to ask a couple of questions of anybody who might know how this works (because, obviously I don't). First off, before we get started, I'm working on a Custom Message System which utilizes future SDK 2.5 method splits for Window_Message, so this is what I need it to work on.

Code:
#==============================================================================
# ** Enable Part II Check
#==============================================================================
if SDK::Parts.include?(2) || 
   SDK::Indidual_Parts.include?('WINDOW_MESSAGE#REFRESH')

#==============================================================================
# ** Window_Message
#==============================================================================

class Window_Message < Window_Selectable
  #--------------------------------------------------------------------------
  SDK.log_branch(:Window_Message, :refresh, :refresh_start, :refresh_text,
    :refresh_text_sub, :refresh_text_loop, :refresh_text_format,
    :refresh_text_color, :refresh_text_line_break, :refresh_show_gold,
    :refresh_draw_text, :refresh_text?, :refresh_choice, 
    :refresh_number_input)
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    refresh_start                   # Refresh Start
    refresh_text if refresh_text?   # Refresh Text if text change
    refresh_choice                  # Refresh Choice setup
    refresh_number_input            # Refresh Number Input setup
  end
  #--------------------------------------------------------------------------
  # * Refresh: Start
  #--------------------------------------------------------------------------
  def refresh_start
    # Clear contents and set normal font
    self.contents.clear
    self.contents.font.color = normal_color
    # Start text position and cursor width
    @refresh_x = $game_temp.choice_start == 0 ? 8 : 0
    @refresh_y = 0
    @cursor_width = 0
  end
  #--------------------------------------------------------------------------
  # * Refresh: Text? Test
  #--------------------------------------------------------------------------
  def refresh_text?
    return $game_temp.message_text != nil
  end
  #--------------------------------------------------------------------------
  # * Refresh: Text
  #--------------------------------------------------------------------------
  def refresh_text
    @refresh_text = $game_temp.message_text   # Set refresh text
    refresh_text_sub                          # Text substitution
    refresh_text_loop                         # Text loop
  end
  #--------------------------------------------------------------------------
  # * Refresh: Text Substitution
  #--------------------------------------------------------------------------
  def refresh_text_sub
    # Control text processing
    begin
      last_text = @refresh_text.clone
      @refresh_text.gsub!(/\\[Vv]\[([0-9]+)\]/) { $game_variables[$1.to_i] }
    end until @refresh_text == last_text
    @refresh_text.gsub!(/\\[Nn]\[([0-9]+)\]/) do
      $game_actors[$1.to_i] != nil ? $game_actors[$1.to_i].name : ""
    end
    # Change "\\\\" to "\000" for convenience
    @refresh_text.gsub!(/\\\\/) { "\000" }
    # Change "\\C" to "\001" and "\\G" to "\002"
    @refresh_text.gsub!(/\\[Cc]\[([0-9]+)\]/) { "\001[#{$1}]" }
    @refresh_text.gsub!(/\\[Gg]/) { "\002" }
  end
  #--------------------------------------------------------------------------
  # * Refresh: Text Loop
  #--------------------------------------------------------------------------
  def refresh_text_loop
    # Get 1 text character in c (loop until unable to get text)
    while ((c = @refresh_text.slice!(/./m)) != nil)
      # If \\, Return to original text
      c = "\\" if c == "\000"
      next if refresh_text_format(c)
      next if refresh_show_gold(c)
      refresh_draw_text(c)
    end
  end
  #--------------------------------------------------------------------------
  # * Refresh: Text Format
  #--------------------------------------------------------------------------
  def refresh_text_format(c)
    return true if refresh_text_color(c)        # Text color
    return true if refresh_text_line_break(c)   # Line Break
    return false
  end
  #--------------------------------------------------------------------------
  # * Refresh: Text Format - Color
  #--------------------------------------------------------------------------
  def refresh_text_color(c)
    # If \C[n]
    if c == "\001"
      # Change text color
      text.sub!(/\[([0-9]+)\]/, "")
      color = $1.to_i
      self.contents.font.color = text_color(color) if color.between?(0, 7)
      return true
    end
    return false
  end
  #--------------------------------------------------------------------------
  # * Refresh: Text Format - Line Break
  #--------------------------------------------------------------------------
  def refresh_text_line_break(c)
    # If new line text
    if c == "\n"
      # Update cursor width if choice
      if @refresh_y >= $game_temp.choice_start
        @cursor_width = [@cursor_width, @refresh_x].max
      end
      # Add 1 to y
      @refresh_y += 1
      @refresh_x = @refresh_y >= $game_temp.choice_start ? 8 : 0
      return true
    end
    return false
  end
  #--------------------------------------------------------------------------
  # * Refresh: Show Gold
  #--------------------------------------------------------------------------
  def refresh_show_gold(c)
    # If \G
    if c == "\002"
      # Make gold window
      if @gold_window == nil
        @gold_window = Window_Gold.new
        @gold_window.x = 560 - @gold_window.width
        if $game_temp.in_battle
          @gold_window.y = 192
        else
          @gold_window.y = self.y >= 128 ? 32 : 384
        end
        @gold_window.opacity = self.opacity
        @gold_window.back_opacity = self.back_opacity
      end
      # go to next text
      return true
    end
    return false
  end
  #--------------------------------------------------------------------------
  # * Refresh: Draw Text
  #--------------------------------------------------------------------------
  def refresh_draw_text(c)
    # Draw text
    self.contents.draw_text(4 + @refresh_x, 32 * @refresh_y, 40, 32, c)
    # Add x to drawn text width
    @refresh_x += self.contents.text_size(c).width
  end
  #--------------------------------------------------------------------------
  # * Refresh: Choice Setup
  #--------------------------------------------------------------------------
  def refresh_choice
    # If choice
    if $game_temp.choice_max > 0
      @item_max = $game_temp.choice_max
      self.active = true
      self.index = 0
    end
  end
  #--------------------------------------------------------------------------
  # * Refresh: Number Input Setup
  #--------------------------------------------------------------------------
  def refresh_number_input
    # If number input
    if $game_temp.num_input_variable_id > 0
      digits_max = $game_temp.num_input_digits_max
      number = $game_variables[$game_temp.num_input_variable_id]
      @input_number_window = Window_InputNumber.new(digits_max)
      @input_number_window.number = number
      @input_number_window.x = self.x + 8
      @input_number_window.y = self.y + $game_temp.num_input_start * 32
    end
  end
end

#==============================================================================
# ** Ends Enable Part II Check
#==============================================================================
end

#==============================================================================
# ** Enable Part II Check
#==============================================================================
if SDK::Parts.include?(2) || 
   SDK::Indidual_Parts.include?('WINDOW_MESSAGE#UPDATE')

#==============================================================================
# ** Window_Message
#==============================================================================
class Window_Message < Window_Selectable
  #--------------------------------------------------------------------------
  SDK.log_branch(:Window_Message, :update, :update_message_show,
  :update_input_number, :update_show_choices, :update_pause, 
  :update_choice_canel, :update_choice_decision, :update_message_idle,
  :update_message_clear, :update_position, :update_cursor_rect)
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    super
    # Step 1 : Create Message
    if @fade_in
      update_message_show
      return
    end
    # Step 2 : Proccess Input Number (if applicable)
    unless @input_number_window.nil?
      update_input_number
      return
    end
    # Step 3 : Process Show Choices (if applicable)
    if @contents_showing
      update_show_choices
      return
    end
    # Step 4 : Update Message Idle
    if !@fade_out && !$game_temp.message_text.nil?
    #if @fade_out == false and $game_temp.message_text != nil
      update_message_idle
      return
    end
    # Step 5 : Clear Message
    if self.visible
      update_message_clear
      return
    end
  end
  #--------------------------------------------------------------------------
  # * Update Show Message
  #--------------------------------------------------------------------------
  def update_message_show
    self.contents_opacity += 24
    unless @input_number_window.nil?
      @input_number_window.contents_opacity += 24
    end
    if self.contents_opacity == 255
      @fade_in = false
    end
  end
  #--------------------------------------------------------------------------
  # * Update Input Number
  #--------------------------------------------------------------------------
  def update_input_number
    @input_number_window.update
    if Input.trigger?(Input::C)
      $game_system.se_play($data_system.decision_se)
      $game_variables[$game_temp.num_input_variable_id] =
        @input_number_window.number
      $game_map.need_refresh = true
      @input_number_window.dispose
      @input_number_window = nil
      terminate_message
    end
  end
  #--------------------------------------------------------------------------
  # * Update Show Choices
  #--------------------------------------------------------------------------
  def update_show_choices
    update_pause
    # Cancel
    if Input.trigger?(Input::B)
      update_choice_cancel
    end
    # Confirm
    if Input.trigger?(Input::C)
      update_choice_decision
    end
  end
  #--------------------------------------------------------------------------
  # * Update Choice Cancel
  #--------------------------------------------------------------------------
  def update_choice_cancel
    if $game_temp.choice_max > 0 and $game_temp.choice_cancel_type > 0
      $game_system.se_play($data_system.cancel_se)
      $game_temp.choice_proc.call($game_temp.choice_cancel_type - 1)
      terminate_message
    end
  end
  #--------------------------------------------------------------------------
  # * Update Choice Decision
  #--------------------------------------------------------------------------
  def update_choice_decision
    if $game_temp.choice_max > 0
      $game_system.se_play($data_system.decision_se)
      $game_temp.choice_proc.call(self.index)
    end
    terminate_message
  end
  #--------------------------------------------------------------------------
  # * Update Pause
  #--------------------------------------------------------------------------
  def update_pause
    # If choice isn't being displayed, show pause sign
    self.pause = $game_temp.choice_max.zero?
  end
  #--------------------------------------------------------------------------
  # * Update Message Idle
  #--------------------------------------------------------------------------
  def update_message_idle
    @contents_showing = true
    $game_temp.message_window_showing = true
    update_position
    self.opacity = $game_system.message_frame.zero? ? 255 : 0
    self.back_opacity = 160
    refresh
    Graphics.frame_reset
    self.visible = true
    self.contents_opacity = 0
    if @input_number_window != nil
      @input_number_window.contents_opacity = 0
    end
    @fade_in = true
  end
  #--------------------------------------------------------------------------
  # * Update Clear Message
  #--------------------------------------------------------------------------
  def update_message_clear
    @fade_out = true
    self.opacity -= 48
    if self.opacity == 0
      self.visible = false
      @fade_out = false
      $game_temp.message_window_showing = false
    end
  end  
  #--------------------------------------------------------------------------
  # * Update Position
  #--------------------------------------------------------------------------
  def update_position
    if $game_temp.in_battle
      self.y = 16
    else      
      case $game_system.message_position
      when 0 ; self.y = 16
      when 1 ; self.y = 160
      when 2 ; self.y = 304
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Update Cursor Rect
  #--------------------------------------------------------------------------
  def update_cursor_rect
    if @index >= 0
      n = $game_temp.choice_start + @index
      self.cursor_rect.set(8, n * 32, @cursor_width, 32)
    else
      self.cursor_rect.empty
    end
  end
end

#==============================================================================
# ** Ends Enable Part II Check
#==============================================================================
end

And then, here's the actual Xtreme Message System to-date, incase anybody needs it for reference.

Code:
#===============================================================================
# ~** Xtreme Message System **~
#-------------------------------------------------------------------------------
# Written by  : Kain Nobel
# Version     : 0.1
# Last Update : 08/20/2008
# Created On  : 08/20/2008
#-------------------------------------------------------------------------------
# * Description :
#
#   This script is supposed to clean up and combine features of many popular
#   message systems, such as Dubealex's AMS and Ccoa's UMS. Unlike other 
#   systems of the same nature, everything is actually set through a simple
#   module known as the "Message" module, can you dig it?
#-------------------------------------------------------------------------------
# * Instructions : Call Script Codes
#
#   XMS.window_mode(number/constant)  # Toggle Window Modes
#   XMS.set_bold(true/false)          # Toggle Text Bold
#   XMS.set_italics(true/false)       # Toggle Text Italics
#   XMS.set_font(name, size)          # Change Text Font Name & Font Size
#   XMS.set_color(Color.new())        # Change Text Font Color
#   XMS.set_faces(true/false)         # Toggle Facesets on or off
#   XMS.justify_window(number/string) # Justify Window Left, Center or Right
#   XMS.justify_text(number/string)   # Justify Text Left, Center or Right
#-------------------------------------------------------------------------------
# * Instructions : In-Message Codes
#
#   \N[#]       # Displays name of actor
#   \V[#]       # Displays value of a Game Variable
#   \G          # Shows the Gold Window
#   \PN[#]      # Displays name of actor in party position id
#   \B          # Autosets Bold text ON/OFF
#   \+B         # Sets Bold text mode
#   \-B         # Unsets Bold text mode
#   \I          # Autosets Italics text ON/OFF
#   \+I         # Sets Italics text mode
#   \-I         # Unsets Italics text mode
#   \TJL        # Justify text to the Left
#   \TJC        # Justify text to the Center
#   \TJR        # Justify text to the Right
#   \WJL        # Justify Window to the Left
#   \WJC        # Justify Window to the Center
#   \WJR        # Justify Window to the Right
#   \W[#]       # Set Message Width
#   \H[#]       # Set Message Height
#   \-W         # Default Message Width
#   \-H         # Default Message Height
#   \FN[font]   # Set Font Name to Custom
#   \-FN        # Set Font Name to Default
#   \FS[#]      # Set Font Size to Custom
#   \-FS        # Set Font Size to Default
#   \WP2        # Set Window Position Top
#   \WP1        # Set Window Position Middle
#   \WP0        # Set Window Position Bottom
#   \HIDE       # Set Window to Transparent
#   \SHOW       # Set Window to Opaque
#   \NM[name]   # Set actor Name
#===============================================================================
#-------------------------------------------------------------------------------
# * SDK Log
#-------------------------------------------------------------------------------
SDK.log('Xtreme Message System', 'Kain Nobel', 0.1, '2008-20-08')
#===============================================================================
# ** XMS
#-------------------------------------------------------------------------------
#   This module is the data & control structure of Kain Nobel's Message System.
#===============================================================================
module XMS
  #-----------------------------------------------------------------------------
  # * Constants
  #-----------------------------------------------------------------------------
  Default_H = 160
  Default_W = 480
  #-----------------------------------------------------------------------------
  # * Message Window
  #-----------------------------------------------------------------------------
  def message_window
    return $scene.message_window
  end
  #-----------------------------------------------------------------------------
  # * XMS.set_font(name, -size)
  #-----------------------------------------------------------------------------
  def self.set_font(name = Font.default_name, size = Font.default_size)
    return if !name.is_a?(String) || !size.is_a?(Numeric)
    @font_name, @font_size = name, size
  end
  #-----------------------------------------------------------------------------
  # * XMS.set_bold(-boolean)
  #-----------------------------------------------------------------------------
  def self.set_bold(boolean = nil)
    if boolean.nil? ; @bold = !@bold
    else            ; @bold = boolean
    end
  end
  #-----------------------------------------------------------------------------
  # * XMS.set_italic(-boolean)
  #-----------------------------------------------------------------------------
  def self.set_italic(boolean = nil)
    if boolean.nil? ; @italic = !@italic
    else            ; @italic = boolean
    end
  end
  #-----------------------------------------------------------------------------
  # * XMS.set_color(r, g, b, a)
  #-----------------------------------------------------------------------------
  def self.set_color(r = nil, g = nil, b = nil, a = 255)
    @font_color = r.nil? ? Font.default_color : Color.new(r, g, b, a)
    return @font_color
  end
  #-----------------------------------------------------------------------------
  # * XMS.set_align(align)
  #-----------------------------------------------------------------------------
  def self.set_align(align)
    if align.is_a?(String)
      case align.upcase!
      when 'LEFT'   ; align = 0
      when 'CENTER' ; align = 1
      when 'RIGHT'  ; align = 2
      end
    end
    if align.is_a?(Numeric) && align.between?(0, 2)
      @align = align
    end
  end
  #-----------------------------------------------------------------------------
  # * XMS.set_name(name)
  #-----------------------------------------------------------------------------
  def self.set_name(name)
    if name.is_a?(String) ; @name = name
    else                  ; @name = ""
    end
  end
  #-----------------------------------------------------------------------------
  # * XMS.reset
  #-----------------------------------------------------------------------------
  def self.reset
    @bold       = Font.default_bold
    @italic     = Font.default_italic
    @font_name  = Font.default_name
    @font_size  = Font.default_size
    @font_color = Font.default_color
  end
  #-----------------------------------------------------------------------------
  # * XMS.set_mode(boolean)
  #-----------------------------------------------------------------------------
  def self.set_mode_text(boolean = false)
    @mode_text = boolean == false ? 'Normal'  : 'Custom'
  end
  #-----------------------------------------------------------------------------
  # * XMS.set_width(-width)
  #-----------------------------------------------------------------------------
  def self.set_width(width = nil)
    @width = width.is_a?(Numeric) ? width     : Default_W
  end
  #-----------------------------------------------------------------------------
  # * XMS.set_height(height)
  #-----------------------------------------------------------------------------
  def self.set_height(height = nil)
    @height = height.is_a?(Numeric) ? height  : Default_H
  end
  #-----------------------------------------------------------------------------
  # * XMS.justify_window(position)
  #-----------------------------------------------------------------------------
  def self.justify_window(position)
    return unless position.is_a?(Numeric) || position.is_a?(String)
    if position.is_a?(Numeric)
      case position
      when 'Left'   ; position = 0
      when 'Center' ; position = 1
      when 'Right'  ; position = 2
      when 'L'      ; position = 0
      when 'C'      : position = 1
      when 'R'      ; position = 2
      when 0        ; message_window.position(4, 16)
      when 1        ; message_window.position(0)
      when 2        ; message_window.position(6, 16)
      end
    end
  end
  #-----------------------------------------------------------------------------
  # * XMS.mode_text
  #-----------------------------------------------------------------------------
  def self.mode_text
    @mode_text = @mode_text.nil?            ? 'Normal'            : @mode_text
  end
  #-----------------------------------------------------------------------------
  # * XMS.bold
  #-----------------------------------------------------------------------------
  def self.bold
    @bold = @bold.nil?                      ? Font.default_bold   : @bold
    return @bold
  end
  #-----------------------------------------------------------------------------
  # * XMS.italic
  #-----------------------------------------------------------------------------
  def self.italic
    @italic = @italic.nil?                  ? Font.default_italic : @italic
    return @italic
  end
  #-----------------------------------------------------------------------------
  # * XMS.font_name
  #-----------------------------------------------------------------------------
  def self.font_name
    @font_name = @font_name.nil?            ? Font.default_name   : @font_name
    return @font_name
  end
  #-----------------------------------------------------------------------------
  # * XMS.font_size
  #-----------------------------------------------------------------------------
  def self.font_size
    @font_size = @font_size.nil?            ? Font.default_size   : @font_size
    return @font_size
  end
  #-----------------------------------------------------------------------------
  # * XMS.width
  #-----------------------------------------------------------------------------
  def self.width
    @width = @width.is_a?(Numeric)          ? @width              : Default_W
    return @width
  end
  #-----------------------------------------------------------------------------
  # * XMS.height
  #-----------------------------------------------------------------------------
  def self.height
    @height = @height.is_a?(Numeric)        ? @height             : Default_H
  end
  #-----------------------------------------------------------------------------
  # * XMS.align
  #-----------------------------------------------------------------------------
  def self.align
    @align = !@align.is_a?(Fixnum)          ? 0                   : @align
    return @align
  end
  #-----------------------------------------------------------------------------
  # * XMS.font_color
  #-----------------------------------------------------------------------------
  def self.font_color
    @font_color = !@font_color.is_a?(Color) ? Font.default_color  : @font_color
    return @font_color
  end
  #-----------------------------------------------------------------------------
  # * Name
  #-----------------------------------------------------------------------------
  def self.name
    @name = @name.is_a?(String)             ? @name               : ""
    return @name
  end
end

#===============================================================================
# ** Scene_Map
#-------------------------------------------------------------------------------
#   The Message Window is now a readable attribute in this scene.
#===============================================================================

class Scene_Map < SDK::Scene_Base
  #-----------------------------------------------------------------------------
  # * Public Instance Variables
  #-----------------------------------------------------------------------------
  attr_reader :message_window
end

#===============================================================================
# ** Scene_Battle
#-------------------------------------------------------------------------------
#   The Message Window is now a readable attribute in this scene.
#===============================================================================

class Scene_Battle < SDK::Scene_Base
  #-----------------------------------------------------------------------------
  # * Public Instance Variables
  #-----------------------------------------------------------------------------
  attr_reader :message_window
end

Code:
#===============================================================================
# ** Window_Message
#-------------------------------------------------------------------------------
#  This window has been enhanced to be affected by the XMS module settings.
#===============================================================================

class Window_Message < Window_Selectable
  #-----------------------------------------------------------------------------
  # * Customizable Constants
  #-----------------------------------------------------------------------------
  Default_Width  = XMS::Default_W.nil? ? 320 : XMS::Default_W
  Default_Height = XMS::Default_H.nil? ? 120 : XMS::Default_H
  #-----------------------------------------------------------------------------
  # * Alias Methods
  #-----------------------------------------------------------------------------
  alias_method :xms_win_msg_initialize,             :initialize
  alias_method :xms_win_msg_refresh_text_format,    :refresh_text_format
  alias_method :xms_win_msg_refresh_text_sub,       :refresh_text_sub
  alias_method :xms_win_msg_refresh_draw_text,      :refresh_draw_text
  alias_method :xms_win_msg_update,                 :update
  alias_method :xms_win_msg_dispose,                :dispose
  #-----------------------------------------------------------------------------
  # * Object Initialization
  #-----------------------------------------------------------------------------
  def initialize
    xms_win_msg_initialize
    @name_window = Window_MessageName.new(self)
  end
  #-----------------------------------------------------------------------------
  # * Refresh : Text Format
  #-----------------------------------------------------------------------------
  def refresh_text_format(c)
    self.width  = XMS.width   if self.width   != XMS.width
    self.height = XMS.height  if self.height  != XMS.height
    case XMS.mode_text.upcase!
    when 'NORMAL'
      self.contents.font.bold   = Font.default_bold
      self.contents.font.italic = Font.default_italic
      self.contents.font.name   = Font.default_name
      self.contents.font.size   = Font.default_size
      self.contents.font.color  = Font.default_color
    when 'CUSTOM'
      self.contents.font.bold   = XMS.bold
      self.contents.font.italic = XMS.italic
      self.contents.font.name   = XMS.font_name
      self.contents.font.size   = XMS.font_size
      self.contents.font.color  = XMS.font_color
    end
    xms_win_msg_refresh_text_format(c)
  end
  #-----------------------------------------------------------------------------
  # * Refresh : Text Sub
  #-----------------------------------------------------------------------------
  def refresh_text_sub
    # Convert Party Actor Name
    @refresh_text.gsub!(/\\[Pp][Nn]\[([0-9]+)\]/) do
      !$game_party.actors[$1.to_i].nil? ? $game_party.actors[$1.to_i].name : "N/A"
    end
    # Set Bold
    @refresh_text.gsub!(/\\[Bb]/)                       { "\003" }
    @refresh_text.gsub!(/\\[+][Bb]/)                    { "\004" }
    @refresh_text.gsub!(/\\[-][Bb]/)                    { "\005" }
    # Set Italic
    @refresh_text.gsub!(/\\[Ii]/)                       { "\006" }
    @refresh_text.gsub!(/\\[+][Ii]/)                    { "\007" }
    @refresh_text.gsub!(/\\[-][Ii]/)                    { "\010" }
    # Text Justification
    @refresh_text.gsub!(/\\[Tt][Jj][Ll]/)               { "\011" }
    @refresh_text.gsub!(/\\[Tt][Jj][Cc]/)               { "\012" }
    @refresh_text.gsub!(/\\[Tt][Jj][Rr]/)               { "\013" }
    # Window Justification
    @refresh_text.gsub!(/\\[Ww][Jj][Ll]/)               { "\014" }
    @refresh_text.gsub!(/\\[Ww][Jj][Cc]/)               { "\015" }
    @refresh_text.gsub!(/\\[Ww][Jj][Rr]/)               { "\016" }
    # Set Window Width
    @refresh_text.gsub!(/\\[Ww]\[([0-9]+)\]/)           { "\017[#{$1}]" }
    # Set Window Height
    @refresh_text.gsub!(/\\[Hh]\[([0-9]+)\]/)           { "\020[#{$1}]" }
    # Default Window Width
    @refresh_text.gsub!(/\\[-][Ww]/)                    { "\021" }
    # Default Window Height
    @refresh_text.gsub!(/\\[-][Hh]/)                    { "\022" }
    # Set Font Name (\fn[""], \-fn)
    @refresh_text.gsub!(/\\[Ff][Nn]\[(.*?)\]/)          { "\023[#{$1}]" }
    @refresh_text.gsub!(/\\[-][Ff][Nn]/)                { "\024" }
    # Set Font Size (\fs[#], \-fs)
    @refresh_text.gsub!(/\\[Ff][Ss]\[([0-9]+)\]/)       { "\025[#{$1}]" }
    @refresh_text.gsub!(/\\[-][Ff][Ss]/)                { "\026" }
    # Set Message Position (\wp0, \wp1, \wp2)
    @refresh_text.gsub!(/\\[Ww][Pp][0]/)                { "\027" }
    @refresh_text.gsub!(/\\[Ww][Pp][1]/)                { "\030" }
    @refresh_text.gsub!(/\\[Ww][Pp][2]/)                { "\031" }
    # Set Message Transparent (\show)
    @refresh_text.gsub!(/\\[Hh][Ii][Dd][Ee]/)           { "\032" }
    # Unset Message Transparent (\hide)
    @refresh_text.gsub!(/\\[Ss][Hh][Oo][Ww]/)           { "\033" }
    # Set Name Box
    @refresh_text.gsub!(/\\[Nn][Mm]\[(.*?)\]/)          { "\034[#{$1}]" }
    xms_win_msg_refresh_text_sub
  end
  #-----------------------------------------------------------------------------
  # * Refresh : Draw Text
  #-----------------------------------------------------------------------------
  def refresh_draw_text(c)
    case c
    # (\B)  : Bold Toggle
    when "\003"
      self.contents.font.bold = !self.contents.font.bold
      return
    # (\+B) : Bold ON
    when "\004"
      self.contents.font.bold = true
      return
    # (\-B)   : Bold OFF
    when "\005"
      self.contents.font.bold = false
      return
    # (\I)    : Toggle Italics
    when "\006"
      self.contents.font.italic = !self.contents.font.italic
      return
    # (\+I)   : Italics ON
    when "\007"
      self.contents.font.italic = true
      return
    # (\-I)   : Italics OFF
    when "\010"
      self.contents.font.italic = false
      return
    # (\TJL)  : Text Justify Left
    when "\011"
      self.contents.x = -16
      return
    # (\TJC)  : Text Justify Center
    when "\012"
      self.contents.x = 0
      return
    # (\TJR)  : Text Justify Right
    when "\013"
      self.contents.x = 16
      return
    # (\WJL)  : Window Justification Left
    when "\014"
      self.x = 8
      return
    # (\WJC)  : Window Justification Center
    when "\015"
      self.x = 320 - (self.width / 2)
      return
    # (\WJR)  : Window Justification Right
    when "\016"
      self.x = 640 - (self.width + 8)
      return
    # (\W[#]) : Default Window Width
    when "\017"
      @refresh_text.sub!(/\[([0-9]+)\]/, "")
      XMS.set_width($1.to_i)
      return
    # (\H[#]) : Default Window Height
    when "\020"
      @refresh_text.sub!(/\[([0-9]+)\]/, "")
      XMS.set_height($1.to_i)
      return
    # (\-W)   : Set Default Width
    when "\021"
      XMS.set_width
      return
    # (\-H)   : Set Default Height
    when "\022"
      XMS.set_height
      return
    # (\FN[font]) : Set Font Name
    when "\023"
      @refresh_text.sub!(/\[(.*?)\]/, "")
      font = $1.to_s
      if font == "" ; self.contents.font.name = Font.default_name
      else          ; self.contents.font.name = font
      end
      return
    # (\-FN)      : Default Font Name
    when "\024"
      self.contents.font.name = Font.default_name
      return
    # (\FS[size]  : Set Font Size
    when "\025"
      @refresh_text.sub!(/\[([0-9]+)\]/, "")
      self.contents.font.size = $1.to_i
      return
    # (\-FS)      : Default Font Size
    when "\026"
      self.contents.font.size = Font.default_size
      return
    # (\WP0)  : Window Position Top
    when "\027"
      $game_system.message_position = 0
      return
    # (\WP1)  : Window Position Middle
    when "\030"
      $game_system.message_position = 1
      return
    # (\WP2)  : Window Position Bottom
    when "\031"
      $game_system.message_position = 2
      return
    # (\HIDE) : Set Transparent ON
    when "\032"
      $game_system.message_frame = 1
      return
    # (\SHOW) : Set Transparent OFF
    when "\033"
      $game_system.message_frame = 0
      return
    # (\NM[name]) : Set Name Box
    when "\034"
      @refresh_text.sub!(/\[(.*?)\]/, "")
      XMS.set_name($1.to_s)
      return
    end
    xms_win_msg_refresh_draw_text(c)
  end
  #-----------------------------------------------------------------------------
  # * Update
  #-----------------------------------------------------------------------------
  def update
    xms_win_msg_update
    @name_window.x |= self.x
    @name_window.y |= self.y
    @name_window.visible = self.visible && XMS.name != nil
    if @name_window.name != XMS.name
      @name_window.set_name
    end
    @name_window.update
  end
  #-----------------------------------------------------------------------------
  # * Position Y
  #-----------------------------------------------------------------------------
  def position_y
    return $game_system.message_position
  end
  #-----------------------------------------------------------------------------
  # * Position X
  #-----------------------------------------------------------------------------
  def position_x
    return 0 if self.x < 320 - (self.width / 2)
    return 1 if self.x == 320 - (self.width / 2)
    return 2 if self.x > 320 - (self.width / 2)
    return 1
  end
  #-----------------------------------------------------------------------------
  # * Dispose
  #-----------------------------------------------------------------------------
  def dispose
    unless @name_window.nil? || @name_window.disposed?
      @name_window.dispose
      @name_window = nil
    end
    xms_win_msg_dispose
  end
end

Code:
#===============================================================================
# ** Window_MessageName
#-------------------------------------------------------------------------------
#   This window (and its slave dummy) handles the Character's Name.
#===============================================================================

class Window_MessageName < Window_Base
  #-----------------------------------------------------------------------------
  # * Public Instance Variables
  #-----------------------------------------------------------------------------
  attr_reader :name
  #-----------------------------------------------------------------------------
  # * Object Initialization
  #-----------------------------------------------------------------------------
  def initialize(win)
    super(win.x, win.y - 32, win.width, win.height)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.contents.font.size = win.contents.font.size + 3
    self.opacity = 0
    @name_background = Window_Base.new(self.x, self.y, self.width, self.height)
    @name_background.contents = Bitmap.new(self.width - 32, self.height - 32)
    @name_background.visible = false
    self.z = @name_background.z = win.z + 10
    self.visible = @name_background.visible = false
  end
  #-----------------------------------------------------------------------------
  # * Set Name
  #-----------------------------------------------------------------------------
  def set_name
    @name = XMS.name
    refresh
  end
  #-----------------------------------------------------------------------------
  # * Refresh
  #-----------------------------------------------------------------------------
  def refresh
    self.contents.clear
    return unless @name.is_a?(String)
    w = self.contents.text_size(@name).width
    h = self.contents.text_size(@name).height
    self.contents.font.color = normal_color
    self.contents.draw_text(0, 0, w, 32, @name)
    self.contents.fill_rect(0, h, w, 1, normal_color)
    @name_background.width, @name_background.height = w + 32, h + 16
    @name_background.contents = Bitmap.new(w, h - 16)
  end
  #-----------------------------------------------------------------------------
  # * Update
  #-----------------------------------------------------------------------------
  def update
    super
    if @name != XMS.name
      @name = XMS.name 
      refresh
    end
    if $scene.is_a?(Scene_Battle) || $scene.is_a?(Scene_Map)
      self.x = @name_background.x = $scene.message_window.x
      self.y = $scene.message_window.y - 32
      @name_background.y = self.y + 12
      if $game_temp.message_window_showing
        self.visible = true
        @name_background.visible = name_back_visible?
      else
        self.visible = @name_background.visible = false
      end
    end
  end
  #-----------------------------------------------------------------------------
  # * Name Back Visible
  #-----------------------------------------------------------------------------
  def name_back_visible?
    return false unless @name.is_a?(String) && @name != ""
    return $game_temp.message_window_showing
  end
  #-----------------------------------------------------------------------------
  # * Dispose
  #-----------------------------------------------------------------------------
  def dispose
    unless @name_background.disposed?
      @name_background.dispose
    end
    super
  end
end

A good majority of basic features have been defined thus far, but there's still a couple things I don't know how to do... first thing I'm trying to do is a Letter-by-Letter message display, as an optional feature.

The second thing I want to do is be able to delay message writting with command codes (like other popular Msg scripts), but I'm not sure how to work that either. Can anybody help me out and give me some tips on how to do this?
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top