Process input once

Hi,
I am trying to read some input to be used with my game but I think sometimes after I have processed the input the key press gets passed down to another input handler and I need to prevent this.

My code:

Code:
document.addEventListener("keyup", function()
{
    if(Input.isPressed())
    {
     // Do something with the input
    }
});

how to code it right so key presses aren't processed more than one time?

thx!
Adding a keyup event listener likely isn't the way to go here because there is already a keyup event listener on the key, that's how the other input handler is able to deal with it in the first place. What is it you're actually trying to do?
Adding a keyup event listener likely isn't the way to go here because there is already a keyup event listener on the key, that's how the other input handler is able to deal with it in the first place. What is it you're actually trying to do?

just trying to read some input to my custom tactical game mode. action key is used to select characters and after moving keeping the position unless cancel button is pressed.
just trying to read some input to my custom tactical game mode. action key is used to select characters and after moving keeping the position unless cancel button is pressed.
From what you've said so far, I can't tell if you're adjusting an event-based battle system on the map, or an extra HUD for the default battle system, or some custom battle system from a plugin, etc.
  1. Exactly where and how do you read the input?
  2. What result do you want?
Screenshots might help!

For an event-based thing it varies. You may be able to make use of the existing event triggers, or you might have to fake your own "trigger" using a loop of some kind, running once per frame.

For a plugin-based thing, you can generally patch an appropriate method. E.g. Window_Command has a setHandler method for binding responses to commands. Or you can run code every frame by patching the update method of an appropriate object, e.g. a relevant game window or its scene.
@caethyril I want to read the input when player is moving on the map. I'll make fictional example to show what I mean. I want the action button to fire gun and escape button to throw handgrenade
OK, that's clearer. 👋

I don't know what your setup looks like, but I would consider making an Autorun event to manually handle all player inputs: movement, gun, grenade. Use Conditional Branch -> [Button] is pressed to check each button, and respond appropriately. Autorun/Parallel events trigger every frame that they're not already running; non-Parallel events also replace normal input responses, e.g. player movement.

If the player can move freely, Parallel may be a better choice than Autorun: then only the gun & grenade inputs need to be checked.

A switch can be used to track whether a button was pressed last frame or not, e.g.

◆If:Button [Cancel] is pressed down ◆If:#0001 Grenade is OFF ◆Control Switches:#0001 Grenade = ON ◆Text:None, Window, Bottom : :Throw grenade! ◆ :End ◆ :Else ◆If:#0001 Grenade is ON ◆Control Switches:#0001 Grenade = OFF ◆ :End ◆ :End
Alternatively you can use Conditional Branch -> Script: Input.isTriggered("cancel"). This will pass only when the button is pressed this frame and was not pressed last frame.
@caethyril wouldn't such event be deleted though when player changes map?
my custom tactical game mode

I want to read the input when player is moving on the map.

the action button to fire gun and escape button to throw handgrenade

Just to clarify some terms:
from your description that sounds like something usually called "Action Battle System" or ABS in the RM-community.

tactical systems on the other hand are more chess-like with limited moves per turn and the skill use still selected in a turn mode.

you might get better advice when using the correct descriptions on what exactly you want.

wouldn't such event be deleted though when player changes map?
you might want to go back to basic tutorials - only map events get removed on map change, not common events.
Just to clarify some terms:
from your description that sounds like something usually called "Action Battle System" or ABS in the RM-community.

tactical systems on the other hand are more chess-like with limited moves per turn and the skill use still selected in a turn mode.

you might get better advice when using the correct descriptions on what exactly you want.

ah yes it's indeed ABS , sorry I forgot the term for it XD

you might want to go back to basic tutorials - only map events get removed on map change, not common events.

ok i totally missed that. it's "common events" right
which you just said xD
Ok this is what I have as first autorun common event but it doesn't show the message when I press ok (enter)


◆If:Button [OK] is pressed down
◆Text:None, Window, Bottom
: :Test!
◆
:End
Autorun common events have a switch. They are only active when their switch is on. Have you turned that switch on?
Autorun common events have a switch. They are only active when their switch is on. Have you turned that switch on?

I didn't know that. well it works now with the switch on. what's the best place to set the switch at start?
It depends when you want your ABS to start (and stop). If you want to turn it on when you enter a map, you can use an Autorun map event like this:

◆Control Switches:#0015 ABS Active = ON ◆Erase Event
Erase Event makes the event disappear until you leave and return to the map. So this turns the switch on once, each time you arrive on that map.
@caethyril thx, what I wanted is to turn the switch on once the battle starts and I just found script solution for that:

Code:
$gameSwitches.setValue(1, true);

Also i had to use Paraller because autorun made my character stuck
still having problem with reading the esc input, when I press esc my script gets called but also the esc menu shows up. this is unwanted

◆If:Button [Cancel] is pressed down
◆If:IsCancelPressed is OFF
◆Control Switches:#0003 IsCancelPressed = ON
◆Script:TacticalBattle.cancelTurn();
◆
:End
◆
:Else
◆If:IsCancelPressed is ON
◆Control Switches:#0003 IsCancelPressed = OFF
◆
:End
◆
:End

maybe the problem is that i run it as Pareller because when i try Autorun the whole game freezes
when i try Autorun the whole game freezes
Yes, that's the point. The primary intent of Autorun events are for cutscenes.

maybe the problem is that i run it as Pareller
That's also correct. Changing it to parallel means all of the default game input will be parsed normally.

You would need, depending on whether you ever want the normal menus and such to function, to either disable them in the code of the game's engine or change your event back to Autorun and add input handlers for character movement.

I wonder a few things from your posts.
1 - Have you done tutorials, practice projects, etc. to learn how RPG Maker itself works (including its fundamental event system) before trying to completely change it?

2 - Are you sure RPG Maker is the best product for your game? There isn't some other engine that starts closer to what you want to make?
Yes, that's the point. The primary intent of Autorun events are for cutscenes.


That's also correct. Changing it to parallel means all of the default game input will be parsed normally.

You would need, depending on whether you ever want the normal menus and such to function, to either disable them in the code of the game's engine or change your event back to Autorun and add input handlers for character movement.

I wonder a few things from your posts.
1 - Have you done tutorials, practice projects, etc. to learn how RPG Maker itself works (including its fundamental event system) before trying to completely change it?

2 - Are you sure RPG Maker is the best product for your game? There isn't some other engine that starts closer to what you want to make?

thx for your msg! I have done few video tutorials for the things I needed. i haven't played much with the vanilla battle system but i think its very final fantasy style so no problem there.

the reason I chose rpg maker is because it's closest, graphically and content wise to shining force (1 & 2) and it has some graphics at start that I can use.

I've actually made lot of progress with my game but making it perfect still takes some time
The Change Menu Access event command enables/disables the pause menu.
the reason I chose rpg maker is because it's closest, graphically and content wise to shining force (1 & 2) and it has some graphics at start that I can use.
I would say other software is closer to Shining Force (as in, it can directly emulate it out of the box). But, then, it also doesn't seem from your descriptions in this thread that you're making something similar to Shining Force.

I just thought it was worth the question, if you're happy with your undertakings then I'm certainly not trying to talk you out of using RPG Maker for it.

Original thread: https://forums.rpgmakerweb.com/threads/process-input-once.162034/