Closing a window with user input

● ARCHIVED · READ-ONLY
Started by shaynec1981 4 posts View original ↗
  1. I'm using Cidiomar's Input script: http://www.rpgmakervxace.net/topic/2551-rgss3-input-full-utf8input-error-found-and-fixed/
     
    and Hime's script that checks for if any is pressed: http://himeworks.com/2014/11/checking-if-any-key-is-pressed/
     
    I have a pop up window with some information that inherits Window_Base. I would like for this window to remain visible until the player presses any key. The key that is pressed will be stored in a variable and the window disposes itself. I know I can get this by:
     

    Spoiler
    Code:
    if Input.any_key_pressed? == true  if Input.pressed?(:LETTER_A)    storedkey = :LETTER_A  end  if Input.pressed?(LETTER_    storedkey = :LETTER_B  end  ...... etc
     
    However, this pop up window is called through a menu. When I press return on the command that makes this window pop up, it automatically registers it as a key press for this new method that creates the pop up window and asks for input.
     
    Here is an example of the script I'm using:
     
    Spoiler
    Code:
    # Init info for bottom windowclass Bottom_Info_Window < Window_Command  def window_width    return 544  end   def window_height    return 366  end   def col_max    return 1  end   def alignment    return 1 # center alignment  end   def make_command_list    add_command("Option 2", :option2)  end end# Init info for top windowclass Top_Command_Window < Window_Command  def window_width    return 544  end  def window_height    return 50  end   def col_max    return 3  end   def alignment    return 1  end   def make_command_list    add_command("Option 1", :option1)  endend# init info for window that pops upclass Window_Popup < Window_Base  def initialize    super(50, 200, 450, 150)  end        def change_text(text)    return unless text.is_a?(String)    contents.clear    draw_text(text, 0, 0, 450, 150)  end   def draw_text(text, x, y, text_width, text_height, alignment = 1)    contents.draw_text(x, y, text_width, text_height, text, alignment)  endend# Creates windows and contains command methodsclass Test_Menu < Scene_MenuBase  def start    super    create_background    create_windows  end   def create_windows    @keyinfowindow = Bottom_Info_Window.new(0, 50)    @keyinfowindow.set_handler(:option2, method(:option2))    @keyinfowindow.set_handler(:cancel,    method(:undowindow))    @keywindow = Top_Command_Window.new(0, 0)    @keywindow.set_handler(:option1, method(:option1))    @keywindow.set_handler(:cancel,    method(:return_scene))    @keyinfowindow.active = false  end   def undowindow    @keywindow.active = true    @keyinfowindow.active = false  end      def option2    @popwindow = Window_Popup.new    @popwindow.change_text("Press a key to close this window.")    if Input.any_key_pressed? == true  # problem area - this is where I'm having      $storedkey = pressed()           # difficulty.      @popwindow.dispose                     @popwindow = nil      @keyinfowindow.active = true      p $storedkey    end  end   def option1    @keyinfowindow.active = true    @keywindow.active = false  end   def pressed    if Input.press?(:LETTER_Q)      return ':Q'    elsif Input.press?(:LETTER_R)      return ':R'    elsif Input.press?(:RETURN)      return ':RETURN'    end  endend
     
    It's around line 88, the option2 method that is causing me a headache. When I leave it as shown, the if conditional is ran through (I'm assuming because of the return key being pressed to get to this method is still being processed as a key being pressed due to have fast the script is running through) and the window disposes very quickly. How do I go about the script waiting at this point in time for further user input instead of using the return key from accessing this method?
  2. Couldn't you just link to the scripts? Generally we prefer people NOT to post scripts when they can just provide a link, for a number of reasons that I won't go into. Also, your failing to put the code into code tags means it's now lost all its formatting. Take a look at what it's done to the code in your third spoiler.
  3. Sure, sorry about that. I'll fix it up ASAP.

    **Edit - all cleaned up!
  4. Have you tried replace Input.press? with Input.trigger?


    I think the latter checks to see if it's been pressed down and then released, while the former just checks if the key is down.