Help - Search - Members - Calendar
Full Version: Window not clearing
RPG RPG Revolution Forums > Scripting > Script Development and Support > RGSS2
Titanhex
So I'm developing a chat system where when you talk to someone a menu pops up. One of those options is "Talk" which preferably brings up the default Show Text box you find in events.

I've found the code for it in the Scripts list under Window_Message. I promptly took to copying and editing it so it could be used via call scripts but still look like the regular Show Text window minus some unnecessary bells and whistles. I've made a window class that is a child of Window_Selectable for this, called Window_Chat.

While the window does show, it doesn't display the face graphic, the text, nor does it clear out properly.

I understand I'm a bit of a novice, but I'm trying my best to take my past scripting knowledge and apply it to this new syntax. Any help is appreciated :3

This is the snippet where the text message is called from:

when 0 #Talk Choice
$talkwindow = Window_Chat.new(@talk, @face, @findex)

The following is the script I have so far:
Window_Chat
CODE
#==============================================================================
# ** Window_Chat
#------------------------------------------------------------------------------
#  This Window is made to mimic Window_Message without all the bells and
#  whistles.  It's callable from a script, where the string is passed through
#  to it.
#==============================================================================

class Window_Chat < Window_Selectable
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize(says, face, findex)
    super(0, 288, 544, 128)
    @says = says                # Message passed to window
    @face = face                # Name of face graphic
    @findex = findex            # Index of face graphic
    @opening = false            # Window opening flag
    @closing = false            # Window closing flag
    @text = nil                 # Remaining text to be displayed
    @contents_x = 0             # X coordinate for drawing next character
    @contents_y = 0             # Y coordinate for drawing next character
    @line_count = 0             # Line count drawn up until now
    @wait_count = 0             # Wait count
    self.contents = Bitmap.new(width - 32, height - 32)
  end
  #--------------------------------------------------------------------------
  # * Create Background Sprite
  #--------------------------------------------------------------------------
  def create_back_sprite
    @back_sprite = Sprite.new
    @back_sprite.bitmap = Cache.system("MessageBack")
    @back_sprite.visible = 1
    @back_sprite.z = 190
  end
  #--------------------------------------------------------------------------
  # * Dispose
  #--------------------------------------------------------------------------
  def dispose
    super
    dispose_back_sprite
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    super
    update_back_sprite
    unless @opening or @closing             # Window is not opening or closing
      if @wait_count > 0                    # Waiting within text
        @wait_count -= 1
      elsif self.pause                      # Waiting for text advancement
        input_pause
      elsif self.active                     # Inputting choice
        input_choice
      elsif @text != nil                    # More text exists
        update_message                        # Update message
      elsif continue?                       # If continuing
        start_message                         # Start message
        open                                  # Open window
        @says.visible = true
      else                                  # If not continuing
        close                                 # Close window
        @says.visible = @closing
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Dispose of Background Sprite
  #--------------------------------------------------------------------------
  def dispose_back_sprite
    @back_sprite.dispose
  end
  #--------------------------------------------------------------------------
  # * Update Background Sprite
  #--------------------------------------------------------------------------
  def update_back_sprite
    @back_sprite.visible = 1
    @back_sprite.y = y - 16
    @back_sprite.opacity = openness
    @back_sprite.update
  end
  #--------------------------------------------------------------------------
  # * Determine if the Next Message Should be Displayed Continuously
  #--------------------------------------------------------------------------
  def continue?
    return false if @says.empty?
    return true
  end
  #--------------------------------------------------------------------------
  # * Start Message
  #--------------------------------------------------------------------------
  def start_message
    @text = ""
    for i in 0...@says.size
      @text += @says[i].clone + "\x00"
    end
    reset_window
    new_page
  end
  #--------------------------------------------------------------------------
  # * New Page
  #--------------------------------------------------------------------------
  def new_page
    contents.clear
    draw_face(@face, @findex, 0, 0)
    @contents_x = 112
    @contents_y = 0
    @line_count = 0
    @pause_skip = false
    contents.font.color = text_color(0)
  end
  #--------------------------------------------------------------------------
  # * New Line
  #--------------------------------------------------------------------------
  def new_line
    @contents_x = 112
    @contents_y += WLH
    @line_count += 1
  end
  #--------------------------------------------------------------------------
  # * Set Window Background and Position
  #--------------------------------------------------------------------------
  def reset_window
    self.opacity = 255
    self.y = 288
  end
  #--------------------------------------------------------------------------
  # * End Message
  #--------------------------------------------------------------------------
  def terminate_message
    self.active = false
    self.pause = false
    @says.main_proc.call if @says.main_proc != nil
    @says.clear
  end
  #--------------------------------------------------------------------------
  # * Update Message
  #--------------------------------------------------------------------------
  def update_message
    loop do
      c = @text.slice!(/./m)            # Get next text character
      case c
      when nil                          # There is no text that must be drawn
        finish_message                  # Finish update
        break
      when "\x00"                       # New line
        new_line
        if @line_count >= MAX_LINE      # If line count is maximum
          unless @text.empty?           # If there is more
            self.pause = true           # Insert number input
            break
          end
        end
      when "\x01"                       # \C[n]  (text character color change)
        @text.sub!(/\[([0-9]+)\]/, "")
        contents.font.color = text_color($1.to_i)
        next
      when "\x03"                       # \.  (wait 1/4 second)
        @wait_count = 15
        break
      when "\x04"                       # \|  (wait 1 second)
        @wait_count = 60
        break
      when "\x05"                       # \!  (Wait for input)
        self.pause = true
        break
      when "\x08"                       # \^  (No wait for input)
        @pause_skip = true
      else                              # Normal text character
        contents.draw_text(@contents_x, @contents_y, 40, WLH, c)
        c_width = contents.text_size(c).width
        @contents_x += c_width
      end
      break
    end
  end
  #--------------------------------------------------------------------------
  # * End Message Update
  #--------------------------------------------------------------------------
  def finish_message
    if @pause_skip
      terminate_message
    else
      self.pause = true
    end
    @wait_count = 10
    @text = nil
  end
  #--------------------------------------------------------------------------
  # * Text Advancement Input
  #--------------------------------------------------------------------------
  def input_pause
    if Input.trigger?(Input::B) or Input.trigger?(Input::C)
      self.pause = false
      if @text != nil and not @text.empty?
        new_page if @line_count >= MAX_LINE
      else
        terminate_message
      end
    end
  end

end


Thanks. I appreciate any guidance or advice to getting this to work.
Titanhex
Bump, the problem has changed as I've been working on this.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2013 Invision Power Services, Inc.