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.

[Resolved] Stop repeat detection of key press

Hey guys. I'm writing a script where you cycle through a list of possible targets with the [Q] and [W] keys. However, I'm having a bit of a problem, because when I so much as look at [Q], it cycles through the whole list. The problem is that the script only detects if the key is down, and doesn't wait for it to be released before detecting again.

I was wondering if there was a way to still have it so that it cycles through the list when the key is pushed down, but then wait for it to be released after before taking another reading.

I'd also like to know how RPGMakerXP does this with the Inventory screen. The game goes to the inventory screen immediately when [Esc] is pressed, but if you keep it held down it doesn't go back to the map screen. It waits for you to release the [Esc] key before it will allow the detection to take you back to the Map Screen. I tried looking at the scripts and there doesn't seem any specific way it does this. Is it because it changes scene in between which somehow resets the detection?

Here's the method that I'm having the issues with.
Code:
  #--------------------------------------------------------------------------

  # * Cycle

  #--------------------------------------------------------------------------

  def VoodooDoll.cycle

   # Cycle Forward

    if (Input.press?(Input::R))

      if (@cur >= @targets.length-1)

        @cur = 0

      else

        @cur += 1

      end

      $game_player.center(@targets[@cur].x, @targets[@cur].y)

      Input.update

    # Cycle Backward

    elsif (Input.press?(Input::L))

      if (@cur <= 0)

        @cur = @targets.length-1

      else

        @cur -= 1

      end

      $game_player.center(@targets[@cur].x, @targets[@cur].y)

      Input.update

    # Confirm

    elsif (Input.press?(Input::C))

      $game_player.moveto(@targets[@cur].x, @targets[@cur].y)

      @mode = 1

    # Cancel

    elsif (Input.press?(Input::B))

      $game_player.center($game_player.x, $game_player.y)

      @mode = 0

    end

  end
 
HarryE":mot09wnt said:
Aha, wow. That was easy. Shoulda read up on my documentation. Thanks, Zer0!

Actually, from what I remember, the documentation on the differences between trigger, repeat, and press is sketchy at best. The real difference is that press always returns true while the button is down, trigger only returns true when the button is pressed down, and not before or after, and repeat returns true as a combination of the above. To see what repeat is like, just try typing up a post and then hitting and holding a button. That's what it does.
 

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