[Solved] Re initializing Window_KeyItem during the game execution?

So in my game, there would need to be two different Key Item selection interface called for different purpose (choices and a quest journal). I had the unpleasant surprise to discover that once Window_KeyItem is drawn, it is set in stone and cannot seemingly be changed.

Here's what I tried to do. Please excuse the horrible ruby syntax:

Code:
def initialize(message_window)
    
    p $game_variables[19]
    
    if $game_variables[19] == 1
    @message_window = message_window
    super(0, 0, 272, 416)
    self.openness = 0
    deactivate
    set_handler(:ok,     method(:on_ok))
    set_handler(:cancel, method(:on_cancel))
    else
      if $game_variables[19] == 2
        #placeholder for now
    @message_window = message_window
    super(0, 0, 272, 416)
    self.openness = 0
    deactivate
    set_handler(:ok,     method(:on_ok))
    set_handler(:cancel, method(:on_cancel))
      else
        #Default fallback
    @message_window = message_window
    super(0, 0, Graphics.width, fitting_height(4))
    self.openness = 0
    deactivate
    set_handler(:ok,     method(:on_ok))
    set_handler(:cancel, method(:on_cancel))
      end
    end


As you can see variable 19 would control the appearance of Window_KeyItem. As it currently stand, it just satay at whatever branch it was first initialized in and cannot be changed.


Is there a way to change this to allow a dynamic change? As my knowledge in Ruby is quite limited, I assume there must be an obvious solution that I am missing. I tried to use various clear and update functions but it failed to do anything (possible error on my part here).
Ruby:
def initialize(message_window)  
    p $game_variables[19]
  if $game_variables[19] == 1 or $game_variables[19] == 2 # placeholder for the time being
    w, h = 272, 416
  else
    w, h = Graphics.width, fitting_height(4)
  end
  @message_window = message_window
  super(0, 0, w, h)
  self.openness = 0
  deactivate
  set_handler(:ok,     method(:on_ok))
  set_handler(:cancel, method(:on_cancel))
end

What I have noticed here is that you never altered the drawing method so its contents will never change at all.
What I have noticed here is that you never altered the drawing method so its contents will never change at all.
This section was just a condition branch placeholder.

Anyway, tuns out that the solution for my problem was basic ruby syntax. I did the following:



In Window_ItemList



Ruby:
  def col_max

    if $game_variables[19] == 1
      #Mission handler
      return 1
    else
      if $game_variables[19] == 2
        #Dialogue interface
        return 1
      else
        #Menu interface
        return 2
      end
    end
   
  end



In Window_KeyItem

Ruby:
  def initialize(message_window)
    #This section was edited by Manpaint
    #Don't touch this section.
    @message_window = message_window
    super(0, 0, Graphics.width, fitting_height(4))
    self.openness = 0
    deactivate
    set_handler(:ok,     method(:on_ok))
    set_handler(:cancel, method(:on_cancel))
  end
  #--------------------------------------------------------------------------
  # * Start Input Processing
  #--------------------------------------------------------------------------
  def start
    #Section edited by Manpaint
    #This control interface sizes
    if $game_variables[19] == 1
      #Mission interace
        self.x = 0
        self.y = 0
        self.width = 272
        self.height = 416
    else
      if $game_variables[19] == 2
        #Dialogue choices
        self.x = 0
        self.y = 0
        self.width = Graphics.width
        self.height = fitting_height(4)
      else
        #Menu interface
        self.x = 0
        self.y = 0
        self.width = Graphics.width
        self.height = fitting_height(4)
      end
    end
   
   
    self.category = :key_item
    update_placement
    refresh
    select(0)
    open
    activate
  end
  #--------------------------------------------------------------------------
  # * Update Window Position
  #--------------------------------------------------------------------------
  def update_placement
    if @message_window.y >= Graphics.height / 4
      #Edited by Manpaint
      #Don't touch this.
     
      if $game_variables[4] == 1
        self.y = 0
        #orig: self.y = 0
      else
      if $game_variables[4] == 2
        self.y = 0
        #orig: self.y = 0
      else
        #Default fallback
        self.y = 0
      end
    end
     

    else
      self.y = 5
      #orig: self.y = Graphics.height - height
    end
  end


As you can see, the engine support "re-initialization" by default. I was under the impression that the keyword super was like a "sequence" but it's just 4 variables. I guess that's the price to pay for not knowing ruby syntax lol.

The above snippets allow you to essentially create a configuration to have multiple Key Item Choice windows. This can be really useful as it can allow you to make some interfaces really quick.
No problem. I just noticed that you ignored that the elsif keyword exists in Ruby. You can start with an if statement followed by as many elsif statements as needed. If you don't care about any other possibility that might take place there, you can end it with the else clause just as you have been doing it so far.

Original thread: https://forums.rpgmakerweb.com/threads/solved-re-initializing-window_keyitem-during-the-game-execution.148188/