Help with looping event issue

Hi. Using this guide from hiddenone I've discovered an issue with looping events which I hope can be resolved. Maybe someone can shed some light on this at least.

Below is a shortened version of the tutorial's example event, but it is functionally identical.
Basically, when the player pushes the "ok" key they can push or pull an object depending on input direction.

However, the "ok" key can be registered twice during the loop, which resets it and results in the player pushing or pulling the block at double speed. This happens frequently if the player is holding a direction key before pushing "ok" when pushing, but also occurs if you just double tap the "ok" key when pushing. Also occurs when pulling if you tap the "ok" again while in mid movement.

PushPullEvent.png


Here is the script in the event if you wanted to quickly recreate it for testing purposes:

if ( ($gamePlayer.direction() == 2 && Input.isPressed("down")) || ($gamePlayer.direction() == 8 && Input.isPressed("up")) || ($gamePlayer.direction() == 4 && Input.isPressed("left")) || ($gamePlayer.direction() == 6 && Input.isPressed("right")) ) { $gameVariables.setValue(5, 1); } if ( ($gamePlayer.direction() == 2 && Input.isPressed("up")) || ($gamePlayer.direction() == 8 && Input.isPressed("down")) || ($gamePlayer.direction() == 4 && Input.isPressed("right")) || ($gamePlayer.direction() == 6 && Input.isPressed("left")) ) { $gameVariables.setValue(5, 2); }
I would guess that your issue is that your loop is continuing to run during the object movement animation and therefore accepting new input commands.

Try breaking the loop immediately after each set of movement commands end and see if that helps 🙂.

Alternatively, you can move the code outside of a loop.
Thanks, Niniann. Unfortunately, neither of those suggestions resolved the issue. I've rebuilt the event in different ways and this issue persists across every version. Action key is just resetting the loop early no matter what.
Hmm, if you move the code outside of a loop, i.e. there is no looping involved, a double press of the action key still double moves the object?
Yes, the issue persists. Firstly, the code has to be part of the loop to work properly (otherwise it only registers the push mechanics). Even so, tapping the action key still resets the loop, resulting in double speed.
Hmm, if you move the code outside of a loop, i.e. there is no looping involved, a double press of the action key still double moves the object?
You definitely don't have to use a loop for this good sir/madam; a loop is generally used for things you want to continually operate. You don't need to the push/pull to continually operate, you want it to happen one piece at a time (in fact I suspect the continual operation is what is causing the issue). Nothing in your code here indicates to me that a loop is a must-have aspect for the code. Everything could be accomplished through conditional branches.

I just built your code in a test project and it works exactly as I would expect it to. It moves continually if I hold the OK button while pressing a direction. This is not a bug, this is how the code is going to run in a loop.

Edit: I can also get continuous movement by rapidly pressing the OK Button just like you're describing; you can endlessly move it in a direction even, won't even be a double movement. Seems to me this is the game processing the rapid button presses as holding the button down while still within the loop. Or if it's not the engine itself and the way it processes button presses, it just hasn't finished running the loop yet to check if the button is still being pressed, and by the time it finishes the movement within the loop, it detects the button is being pressed again and repeats the process.
What I'd like to achieve is:
  1. Holding the action key next to a movable object 'locks' the player to the event.
  2. Moving forwards or backwards while 'locked' moves the object with the player.
  3. The player just needs to hold the direction input, no need to push again for each movement.
  4. Releasing the action key 'unlocks' the player from the event.
Point 3 is where the loop comes in. If this would be possible without a loop, I'd jump for joy.
Ahhh, I see now why you want a loop here.

After doing some further testing I believe I know exactly why you're experiencing this sped up movement when holding down the Ok Button.

This is because, by default, holding down the Ok Button in the RPG Maker engine is a "fast forward" mechanism through events in progress, including loops.

For another example of this, make an Action Button event that has a bunch of events moving around and hold the Ok Button down. It will speed up all of the movement contained in the event.

You will need to change that functionality within the engine (or have some code/plugin command that temporarily disables it nestled within your push/pull event) if you want your code to work like you want it.

As to why this only occurs when holding a direction key before you press the Ok Button (which I noticed as well), I couldn't tell ya. Maybe because the engine is processing the Ok Button being held down after the direction key, which it would interpret as the user holding the Ok Button after the event has started. That being said, it is definitely the reason why the movement speeds up when you press the Ok Button in quick succession.

But I'm pretty dang sure at this point it's nothing wrong with your code itself, just the way the engine is handling the Ok Button being held down during event processing.
Okay, that makes sense. Thanks for investigating, I would have never thought that. Now, I guess I have to start a new thread for that specific issue. Thanks again.

Edit: Thanks to Aesica for telling me this. To disable fast forward for scenes and battle:
Scene_Map.prototype.isFastForward = function(){ return false; }; Window_BattleLog.prototype.isFastForward = function(){ return false; };
Okay, that makes sense. Thanks for investigating, I would have never thought that. Now, I guess I have to start a new thread for that specific issue. Thanks again.

Edit: Thanks to Aesica for telling me this. To disable fast forward for scenes and battle:
Scene_Map.prototype.isFastForward = function(){ return false; }; Window_BattleLog.prototype.isFastForward = function(){ return false; };
Awesome, glad you got it worked out now. 🙂

Best of luck with your project,
-Niniann

Original thread: https://forums.rpgmakerweb.com/threads/help-with-looping-event-issue.163044/