Wait for user input script

● ARCHIVED · READ-ONLY
Started by Amaggard 7 posts View original ↗
  1. Can somebody help me with my script? I am trying to make it to where the game will wait for user input on the keyboard before going to the next line, but I haven't found anything. This is what the part that needs to wait for user input looks like:

    def exit_command @window = New_Text_Creator.new @window.change_text("Are you sure you want to exit?") #line that needs to wait for user input add_command("Yes", :exit) add_command("No", :cancel) end
    I have tried plenty of methods, but none have worked. This is what I've tried:

    def exit_command @window = New_Text_Creator.new @window.change_text("Are you sure you want to exit?") Input.press?:)CTRL) #control is one of the constants used by Input.press? add_command("Yes", :exit) add_command("No", :cancel) endend
    Code:
      def exit_command    @window = New_Text_Creator.new    @window.change_text("Are you sure you want to exit?")    if Input.press?(:CTRL)    add_command("Yes",  :exit)    add_command("No",   :cancel)  endend
    Code:
      def exit_command    @window = New_Text_Creator.new    @window.change_text("Are you sure you want to exit?")    if Input.press?(:CTRL)    do    add_command("Yes",  :exit)    add_command("No",   :cancel)  endend
    Code:
      def exit_command    @window = New_Text_Creator.new    @window.change_text("Are you sure you want to exit?")    case BUTTON    when Input.press?(:CTRL)    add_command("Yes",  :exit)    add_command("No",   :cancel)  endend
    Code:
      def exit_command    @window = New_Text_Creator.new    @window.change_text("Are you sure you want to exit?")    yield until Input.press?(:CTRL)    add_command("Yes",  :exit)    add_command("No",   :cancel)  endend
    If anyone knows a better way to make it wait for user input on the keyboard (or any way at all), then could you please tell me how to make my script wait!? I'm sure it isn't really that hard, but I haven't been able to figure it out, so any help would be appreciated!
  2. Is this during an event?
  3. You want to make a script that shows a prompt then waits for the user to press a key and THEN gives the yes/no options?


    You don't have a loop that gets input.


    You need to put a loop that contains Graphics.update and Input.update commands and then checks if a key is pressed, to break out of the loop.


    But I really question what you're trying to do. Why not just give them the yes/no prompts straight away?
  4. While I agree with Shaz as to why not just them the prompt to quit immediately (unless you have your reasons to do it as you're trying now), the reason most of your methods aren't working (aside from the lack of loops) is that you're not setting up your if statements properly. This one is the most correct:

    def exit_command @window = New_Text_Creator.new @window.change_text("Are you sure you want to exit?") if Input.press?:)CTRL) add_command("Yes", :exit) add_command("No", :cancel) endendHowever, you're missing the 'end' that tells Ruby where the if statement stops. If you don't do that, Ruby will get confused and won't run your game (You'll get a Syntax error)

    Try this instead:

    def exit_command @window = New_Text_Creator.new @window.change_text("Are you sure you want to exit?") if Input.press?:)CTRL) add_command("Yes", :exit) add_command("No", :cancel) end endendThis, however, still isn't very good, because it's only run once. You'll need this in a loop for it to be reliable. Since this is a check for exiting, it would make sense to me to put this in the update method. Ex:

    def update <update your scene/window here> if Input.press?:)CTRL) <process your quit prompt here> end endendupdate is called once per frame on both Windows and Scenes within RPG Maker.
  5. @Tsikihime, No, it is the player menu.

    @Shaz, Well, I wanted it to have the message "Are you sure you want to quit?" display in the middle and have an arrow signaling to continue and then when the play presses the input, I'd have the next box pop over it and have yes and no options. I guess I can just put it below the first message box to begin with instead of having it go over it after input.

    @Zalerinian, Thanks for showing me how to fix it with those scripts, but I am now just going to show the options immediately. Also, this:

    def exit_command @window = New_Text_Creator.new @window.change_text("Are you sure you want to exit?") if Input.press?:)CTRL) add_command("Yes", :exit) add_command("No", :cancel) end endend...is within a class.... Does that mean that there would have to be 4 ends in a row...? o_O
  6. Before this gets closed, now I need some more help. I want to display the message and choice within one text box. Do you know how to combine my scripts to make it within one box? This is all of the script:

    #This is for the "Are you sure you want to quit" message boxclass New_Text_Creator < Window_Base def initialize() super( 122, 170, 300, 75 ) end def change_text ( text ) contents.clear return unless text.is_a?(String) draw_text(text, 15, -200, 300, 450) #This is defined below end #-------------------------------------------------------------------------- # * Draw Text # args : Same as Bitmap#draw_text. #-------------------------------------------------------------------------- def draw_text(text, x, y, text_width, text_height, alignment = 0) contents.draw_text(x, y, text_width, text_height, text, alignment) #This is the contents of this message box endend#This is used by doing: # new_text_creator = New_Text_Creator.new# new_text_creator.change_text(#Insert_Text)
    Code:
    #This_is_the_scene_that_is_ultimately_calledclass Scene_Exit < Scene_MenuBase  def start    super    create_command_window  end    def create_command_window    @command_window = Scene_ExitCommand.new  #Creates_new_instance_of_ExitCommand    @command_window.set_handler(:exit,       method(:exit_game))    @command_window.set_handler(:cancel,     method(:return_scene))  end  #--------------------------------------------------------------------------  # * Makes the exit command  #--------------------------------------------------------------------------  def exit_game    exit  endend
    Code:
    #This_makes_the_window_for_Scene_Exit_and_makes_the_commands_themselvesclass Scene_ExitCommand < Window_Command  def initialize    super(230, 170)  end    def make_command_list    exit_command  end    def window_width    return 190  end    def window_height    return 175  end    def exit_command    add_command("Yes",  :exit)          add_command("No",   :cancel)  endend
    If you could help me but putting these 2 message boxes into one, that would be amazing!
  7. That is a new problem, and will require a new thread in RGSS3 Script Requests.


    This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.