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] Input delay woes

Lystar

Member

Good evening all,
I've been avoiding making this post. I'm stubborn and thought I could solve this problem on my own. However after being hung up all week on such a seemingly simple problem I thought it was time to reach out for a hand. Sorry if this is solved somewhere on the forum already, I did a search but didn't find anything that quite fit with what I need.

My problem is with the CMS I'm working on in RGSS2 (RPG Maker VX).
Everything was going smoothly until I got around to scripting the item screen. When I hit enter on one of my items I want a target select screen to highlight and ask for player input (i.e Who do you want to use "x" item on?) and then not do anything until the enter key (or whatever) is pushed again. This is all working perfectly EXCEPT when I hit enter the first time on my item it immediately uses the item on the default target. I can then go ahead and select another target (if I had more than 1 of the item) and use the selected item. Its like there is no delay before the game checks to see if the return key is pushed after switching to the target screen.

The item menu consists of 1 scene with 2 important windows: my item selection window & the target selection window. There are help windows on screen with item quantities and item descriptions etc but they aren't an issue. The cursor controls (i.e. Up, Down, Left, Right) for each window is handled by my window classes while the Return key and Escape key processing are handled within the item Scene. (Is that not the proper way to do it?)

I can't really post the code I'm using, as its in a huge mess from me swapping lines and rearranging things constantly trying to solve the issue. I thought it was just a problem with Input.trigger? vs Input.press? or something like that but I've tried all the input methods without success.

I can try to map out the process my menu takes to use an item if that will help:

>> Item Screen Appears.
    ==> Player selects desired item
>> Target Screen fades in (it is semi-transparent until item is selected)
  ==> Item is used immediately **** This is the Problem ****
  ==> Player can then chose a target to use the item on

From this brief explanation, can anyone venture a guess or give a suggestion to help me out?

Thanks in advance.
 

khmp

Sponsor

I just made an configurable Input script for someone for VX and had the exact same problem with a Input.trigger? call. The Input.trigger? key was being triggered twice before the buffer had a chance to remove the key's state. I ended up cheating like a coward and using a sleep call. sleep(0.1). Although just now I went back and took it out and it works fine. I'm confused on this too now.
 
What I did in a similar case is to have a variable that starts at 0 and adds one constantly while enter is held down, and then resets to 0 when you let go. Then wherever you're checking that enter is pressed check if the variable is equal to 1. Of course, this won't work if both checks are made on the same frame... however you could just manually add one to it after the first check. Not the best way I think, but it works.
 
Strange. That might be a bug in VX. Well if that is the case, here is a quick script that should fix that problem (mind you I am semi-drunk, so if it doesn't work, let me know, and I didn't bother opening RMVX):

Code:
module Input
  class << self
    @@seph_posvxinputfix_triggers = []
    unless self.method_defined?(:seph_posvxinputfix_input_trigger?)
      alias_method :seph_posvxinputfix_input_trigger?, :trigger?
      alias_method :seph_posvxinputfix_input_update, :update
    end
    def trigger?(constant)
      if @@seph_posvxinputfix_triggers.include?(constant)
        return false
      end
      @@seph_posvxinputfix_triggers << constant
      return seph_posvxinputfix_input_trigger?(constant)
    end
    def update
      @@seph_posvxinputfix_triggers.clear
      seph_posvxinputfix_input_update
    end
  end
end

However, I am skeptical on there being an Input error, unless the update method isn't being called (assuming they manage their input checks by creating arrays of pressed keys on the update method, as seen in Near Fantastica's Keyboard module).

If you would care to show your code, here or though a PM, I could see for sure if it was a VX error or a possible error in your code (if your update method branches, but doesn't return (see below), this could cause an error):

Code:
class Scene_Blah
  # ...
  def update
    if @your_window1.active
      update_yourwindow1
    end
    if @your_window2.active
      update_yourwindow2
    end
  end
  def update_yourwindow1
    if Input.trigger?(Input::C)
      @your_window2.active = true
    end
  end
  def update_yourwindow2
    # ...
  end
end

As you can see in the code below, update_yourwindow1 method operates, if you press C, your window 2 method becomes active, then back to your update method, the your window 2 method is active, so it proceeds to the second update method without a break. Because the Input module has not been updated yet, the trigger method has not had a change to clear the keys states.

That's just my theory on whats happening, because I have done it myself.
 

khmp

Sponsor

You know what that's exactly what I was doing originally. I was skipping Input.update. I later threw in returns which corrected this problem, and didn't even realize it. Thanks for posting those thoughts SephirothSpawn.
 

Lystar

Member

Seph, that's pretty much my update method exactly.

I'm going to toss in some returns and see if it works.
Thanks for the help.

EDIT:

PERFECT.
This can be marked as resolved. It works like a charm now.
 

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