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.

Input problem

Hi guys, How do I know the input number command has finished ?
I'm calling rmxp's input command from a script.
It works, but.. consider the following code:
Code:
# a method showing the input window

$game_system.show_input(x,id,8,2)

#use the data stored in $game_variables[id]

use_the_data
line 4 executes before the input window even shows up :(
I've tried:
Code:
loop do

      # Update game screen

      Graphics.update

      # Update input information

      Input.update

      # Abort loop if input finished. I made message_waiting an attr_accessor

      if ! $game_system.map_interpreter.message_waiting

        break

      end

    end

But the result is an endless loop, as RMXP always executes the whole code first, and then the message windows.
Is there no way around it?
If I won't do it via script, I'll be forced break my scene, go to scene_map and call a common event to do the input. Help?
 
Hmm. I think I got it.
Someone may find it useful. This scene will show the input number screen + text
and return the number. So you can have a scene asking for input, without using an event command and a game variable.

Edit: The older version was buggy. Use this instead.

new window_Input
Code:
class Window_Input < Window_Message

  

  def initialize(text, digits)

    super()

    @var_id = 1

    start_input(text, digits)

  end

  

  def start_input(text, digits)

    @old_data = $game_variables[@var_id]

    $game_variables[@var_id] = 0

    $game_temp.message_text = text

    $game_temp.num_input_variable_id = @var_id

    $game_temp.num_input_digits_max = digits

    $game_temp.num_input_start = 1  # from_line

  end

  

  def finished?

    return @input_number_window.nil?

  end

  

  def get

    loop do

      # Update game screen

      Graphics.update

      # Update input information

      Input.update

      # Frame update

      update

      # Abort loop if screen is changed

      if @input_number_window.nil?

        break

      end

    end

    number = $game_variables[@var_id]

    $game_variables[@var_id] = @old_data

    return number

  end

  

end
To use, add a window_input to your scene:

@window = Window_Input.new(text, digits)
@your_number = @window.get
@window.dispose
 

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