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.

Double button press

I need to check one button, and wait 1 second while waiting for another press of the same. Its just i don't understand input module or is that trully i have to check framecount and/or make some algorithm?
Now i'm using two counters, one for pulsations and other for frames... and other to turn on/off all, but i think there will be a better way.
 
I haven't used rmxp in a while, but the following should work.
Suppose the "C" button is the button that needs to be pressed:

Go into Game_Temp and under initialize, put @flag = false and add attr_accessor :flag with the other
attr's. Make a common event and tell it to wait 10 frames, script: $game_temp.flag = true, wait for x ammount of frames, $game_temp.flag = false (x ois how long it should wait until its been too long to hit the button the second time. Finally, go to the update loop of wherever this button pressing takes place and add
if Input.trigger?(Input::C)
$game_temp.common_event_id = ID of event above
end
if $game_temp.flag
Stuff you want to happen
end

You probably want to use something other than C for this.
If there's anything I left out, it doesn't work, or you want something more specific; feel free to let me know:)
 

Scuff

Member

There's one problem with your code, "if Input.trigger?(Input::C)"
RMXP does not work like that, if you input::C, the key "C" is not the key that will be called, unless you are using a Full Keyboard Script.
 
I'm not sure what you mean, C is the the action button. The input module contains a number of keys that are already mapped, like A, B, C, L, R, etc. In fact, if you look at the update loops for game_map, or any window that allows you to select things you'll notice similair code. The C in my code is a constant, not the actual key "C". Finally, if you press F1 while in game, you'll notice that you can remap what keys belong to A,B,C, etc.

*Edit
The above is why I suggested he not actually use C, but some other key, say A.
 
To clarify this mess: 'C' is a constant within RGSS that stands for the 'confirm' key. The default mapping for that key are '<Return>', '<Space>' and 'c' keys. So, while usually those constants aren't their respective letters on the keyboard, in case of C, they are.

For the script, I'm puzzled if it's about "if button is pressed again after at least one second waiting time" or "if button is pressed before 1 second waiting time". Either way, yeah, you should use framecount for this - depending on your maker, 40 or 60 frames per second. If you have it running in a custom scene, you might want to add a variable handler into the update method, like this:
Code:
def initialize

  # (...)

  @frametimer = 0 # initializes frametimer variable

end

 

def update # updates once per frame

  # (...)

  @frametimer -= 1 # decreases the leftover time by one frame

  if Input.trigger?(Input::C) # if confirm button is pressed

    if @frametimer > 0 # checks if player still has time for the second keypress

      p 'You pressed the second button in time!' # whatever happens when successful

    else # if the second keypress isn't possible anymore

      @frametimer = 60 # set the leftover time to 1 second/60 frames

    end

  end

  # (...)

end
 

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