Checking for key press prevents action button from working

Hi guys,


I have a script setup to check for a key press which I mapped previously.  I then use a switch based on the key press to call a common event to turn on/off a lantern lighting effect.  This is run within a parallel process event and is working fine.  The problem is that now the game fails to respond to the action button for other events on the map.  My understanding is that a parallel process should be running along side everything else but seems to be hogging the update for key presses.  When I disable the event everything works fine so I know my script is the issue.  Any ideas?

Capture.PNG
Perhaps it's cause by the lag of that parallel? By default parallels run sixty times per second unless you include waits in them - I would never make such a process without at least a wait(5).


Additionally, if the script command forces you to wait for a key press, that might break the entire game loop - I don't know enough of the input command you used to decide if that one is critical or not.
Thanks for the reply but I tried adding a wait and while it does make it possible to trigger an event with the action button, it misses key presses and causes you to have to press it several times to have it detected.  As far as the common events, all they do is show one picture or the other based on the value of the variable ce so nothing complicated.  The movement keys and other mapped keys work just fine and there are no delays anywhere in the common events so this really doesn't make sense.  Any other thoughts?
I take this is for mobile as it looks like you tracking the location of mouse. If so you could set virtual keys if needed to be
The tracking of the player x and y is used to center the graphic on the player it has nothing to do the with the mouse.
Sorry read that wrong -
I solved this by overriding the Game_Player.prototype.update() method and just scripting the functionality I need but I feel this must be a bug because only the action button stopped working.  Who knows.
No, it is not a bug - it is intentionally done this way to allow a number of other advantages. and if you had given us the info we asked for, we could have shown you how to do it without modifying the game engine.
@AndarExcuse me but you didn't ask me for any information not to mention your suggestion of adding a wait to improve lag is illogical and did not work at all.  The more times a method is called per frame the more chance the polling of the keyboard has to pick up a key press.  Since you claim this is not a bug, please explain to me how it's an advantage to allow a script command to check for a key press and then stop the action button from working? 


With all due respect, you obviously don't know what you're talking about.  I may not be an expert with RPG Maker, but I have been writing programs for over 20 years and the principles of game programming are pretty much the same regardless of the language used.  In addtion, overriding a method does not modify the game engine only it's behavior which is the idea with a custom script right?


Since you apparently know how to fix it, I'm listening.
your suggestion of adding a wait to improve lag is illogical and did not work at all. 

No it is not, because the way how the wait command works internally.


Wait basically says "skip processing this event for x frames". In the case of regular events that results in a wayt, but in the case of parallel processes this means that the parallel is not executed sixty times per second, reducing the required processing power and thereby reducing lag.


However, it requires some experimenting to get the correct number of waits - too many and the parallel will not detect what it is waiting for, too few and the number of parallels will lag the entire game loop (thereby resulting in the game not being able to do anything).


overriding instead of aliasing a method can cause problem, because most scripts and plugins add themselves to existing functions by aliasing and calling the old method. That is why the order of scripts/plugins has become one way to solve compatibility issues. completely overriding and replacing a method only works once - as soon as another plugin does the same, you get compatibility problems.


And the main question/problem with your original code is still the way the script command works - I simply don't know why you're using script commands for something that can be done by conditional branches. However, it doesn't matter in case of the second and third part of the script as that should have no difference.


However, as I said above the first part of the script might be the cause and breaking the game loop itself.


I know for fact that the engine automatically handles input into the game loop correctly if you're using conditional branches to check for key presses.


But I don't know if that scripted input method does the same - if that command creates an input wait outside the regular game loop, then that will cause the engine to skip the other checks for triggers. Because any multiple check for different inputs can only work if they are all checked in the same loop. If you create your own loop, then only the parts inside that loop gets checked and the rest ignored.
reducing the required processing power and thereby reducing lag.

What?  I have had simulations with HUNDREDS of objects on the screen at one time all checking for collision against the other EVERY frame without lag.  The parallel process means it runs "side by side" with the rest of the game but in reality that is an illusion created by the developers.  Under the hood, ALL game objects are updated every frame and by inserting a wait command in an event, you are creating a bottle neck.  With that said, it is possible that keyboard input might be separate from the main game loop.  I will have to investigate that possibility by reviewing the core scripts.

I simply don't know why you're using script commands for something that can be done by conditional branches.

EDIT:  You are half right.  I did not see that on page 4 of the conditional branch you can check for a key press and react accordingly.  Unfortunately which keys I can select from is limited.  I used the 'L' key to switch my lighting effect on and off so it seems I still need to resort to a custom script to make this work.  Not to mention, the conditional branch only checks to see if a key is being held down but I need to check for a key press which is something that only fires once.

overriding instead of aliasing a method can cause problem, because most scripts and plugins add themselves to existing functions by aliasing and calling the old method.

The function has been aliased I simply used the wrong terminology to describe it.  In Java we override the method of the super class and if we want to call the original method we can do so from the child class.  I forgot that JavaScript refers to this as an alias for a method.  The original method was properly aliased with my new code.

However, as I said above the first part of the script might be the cause and breaking the game loop itself.

Looking at the method in the script it simply returns true or false as to whether a key was just pressed.  Nothing processor intensive here that would explain the problem.

Because any multiple check for different inputs can only work if they are all checked in the same loop. If you create your own loop, then only the parts inside that loop gets checked and the rest ignored.



If that is true, why am I still able to move the character?  Open the menu etc?  Why is it that only the action button fails to be recognized?

Original thread: https://forums.rpgmakerweb.com/threads/checking-for-key-press-prevents-action-button-from-working.58164/