Making an action button-triggered event run parallel

I have a simple common event for the actor on the map to swing a weapon, basically it switches character images when the OK button is pressed, to simulate the swing of the sword:
Sword Use.png

I have tried to set up an enemy or obstacle(stone block) to be destroyed when the player presses action button to interact with them. This is just a simple way of doing it rather than an Action RPG script/plugin. However, I think the "Sword Use" common event is somehow blocking or delaying the Enemy/Obstacle from carrying out its event process, which is this:
Block destroy.png

If I press the OK button, while the "Sword Use" common event is in effect, while adjacent to the obstacle, it doesn't carry out it's process of animation and self destruction, unless I repeatedly press "OK" and it will do it on the 6th or 7th press.
If I don't have the whole "Sword Use" event engaged, and just walk up to the obstacle and press OK, it carries out it's event process right away.
Is it the amount of frames I am waiting in the sword use event? I don't think so, because I've tried swinging the sword, and waiting but nothing happens to the obstacle. I have to press OK a bunch of times, and then it does it's thing. I thought perhaps the obstacle event needs to run parallel so it's not waiting for the Sword Swing OK button common event to run through.
Any advice would be appreciated.
While the player is going through a forced movement, normal player controls are suspended. This includes using the Action Button to activate events.

Try splitting up the player move route in your Parallel event, so instead of this:
  • Set Movement Route: Direction Fix ON, Change Image, Wait, Change Image, Wait, ...
You have this:
  • Set Movement Route: Direction Fix ON, Change Image.
  • Wait 10 frames.
  • Set Movement Route: Change Image.
  • Wait 10 frames.
  • ...
While the player is going through a forced movement, normal player controls are suspended. This includes using the Action Button to activate events.

Try splitting up the player move route in your Parallel event, so instead of this:
  • Set Movement Route: Direction Fix ON, Change Image, Wait, Change Image, Wait, ...
You have this:
  • Set Movement Route: Direction Fix ON, Change Image.
  • Wait 10 frames.
  • Set Movement Route: Change Image.
  • Wait 10 frames.
  • ...
Thanks for this. I tried that, and it did make the action button-activated event run a bit sooner, but still is delayed. I thought it would for sure work with spacing you suggested, like after the first forced movement. It might be a matter of trial and error, moving the spacing around.
It caused another problem with the movement of my character, though, as now if I press OK repeatedly the actor can slide across the screen swinging, which I'll have to fix somehow.
Several things.

First, please do not crop your screenshots too far, we should always get the full event window.
It is especially important to see the page numbers and triggers of events as that can change a lopt.

Second, have you considers using the opposite approach?
Clicking OK toward an event triggers it without too much hassle, so if you make your enemy event trigger on action button and the player does this, then have the enemy event play the sword animations on the player.

That won't work in all cases (and especially not if you want to event an ABS), but it is a viable approach for several puzzles where the player must remove obstacles.
Several things.

First, please do not crop your screenshots too far, we should always get the full event window.
It is especially important to see the page numbers and triggers of events as that can change a lopt.

Second, have you considers using the opposite approach?
Clicking OK toward an event triggers it without too much hassle, so if you make your enemy event trigger on action button and the player does this, then have the enemy event play the sword animations on the player.

That won't work in all cases (and especially not if you want to event an ABS), but it is a viable approach for several puzzles where the player must remove obstacles.
First point: I will do this in the future. Sorry about that.

Second. I will try that. I wanted to have the character play the sword swing regardless if there is any enemy in front of him. That's perhaps a frivolous, impractical desire, that I should abandon to make this work.
or you could do both, but that can look wrong.
have the parallel check play the swing as normal, just ignoring any target. and have the target play the swing when it was triggered as well.

problem with that is that the two different animations can intersect, if the player was swinging the sword and then triggers the target before that swing was completed.

One of the most important aspects of game development is to not set yourself into any form of dead end. And never to forget that what the player sees is not the same as what really happens in the background game mechanics.
I think what people typically do for this kind of system is use code in your parallel event to look at the tile the player is facing, and if an event is on it, trigger it.

That way the trigger is being called by your sword swing and not relying on an additional button press to actually trigger the map event traditionally.
Please show the whole Eventcode of your Common Event Picture for the Sword Slash, there could be other code in it causing the delay. Because normaly the Condition in the Common Event should trigger just fine.

Edit: And which Event contains the code if Slash hit Event? Having that split up over multiple
Parallel Events could also cause delays in case you use more than one Parallel Event for all the
individual Slash Targets. Knowing more about that could help us better guessing a cause for this.
Maybe a Wait command in the wrong Place, could also cause this.
Please show the whole Eventcode of your Common Event Picture for the Sword Slash, there could be other code in it causing the delay. Because normaly the Condition in the Common Event should trigger just fine.
The code in the picture just repeats for each direction faced. There's nothing else in the event.

RPG screen 1.png

rpg screen 2.png



Edit: The obstacle event itself contains the code for when it is hit, as it's just triggered by interacting with it. I'm not using an action plugin with hitboxes or anything like that.
That looks correct so far. I can spot no Error in it.

Can you show the whole Eventpage with Hit detection code of yours, please?
That looks correct so far. I can spot no Error in it.

Can you show the whole Eventpage with Hit detection code of yours, please?
Untitled-3.png

There's no hit detection, it's just supposed to be triggered when interacted with by action button. When you walk up to the block, and press OK, the player's sword swing is supposed to play, and the block is supposed to explode and then switch off.
It's probably very rudimentary and clunky. I just don't know what I'm doing, really.
I think what people typically do for this kind of system is use code in your parallel event to look at the tile the player is facing, and if an event is on it, trigger it.

That way the trigger is being called by your sword swing and not relying on an additional button press to actually trigger the map event traditionally.
So I'd start with this, something to check if the tile has an event? I'm not sure where to go from there.
Untitled-1.png
There's no hit detection, it's just supposed to be triggered when interacted with by action button.
This is helpful information. That makes me more likely to guess that it could be a very rare timing circumstance which iam not good at explaining at.
But in the same Frame the Common Event would do some things and the Event004 also when clicked,
some Event commands need a Frame to get initialised, else they could be overwritten before they start. Cant say for sure which one it is in your case, but i remember running into something like that in the past. It could be solved. Hopefully i dont remember the wrong solution. But you could try this:

In Event 004 make your first Eventcommand be:
Eventcommand "Wait" and select 2 Frames. Than the rest of the Code as was.

Let us know if it worked.
Ah, I overlooked that you would want the player to remain fixed in place during the swing. 😴

For what Turan suggested, you could set up a loop that checks for input for the duration of the animation, like a QTE. Something like this may work for you:
  • Turn on switch X.
  • Move Route: etc
    • Do not wait for completion (want to process loop during move route).
    • Turn off switch X at the end, to end the loop.
  • Loop:
    • Wait: 1 frame.
    • If switch X is off:
      • Break loop.
    • If action button is triggered:
      • Script: $gamePlayer.checkEventTriggerThere([0, 1, 2]); $gameMap.setupStartingEvent();
The script here is a subset of what happens when you press the action button in-game: it starts an event in front of the player (if present).

You will also probably want to add an event ID check, via Get Location Info.
This is helpful information. That makes me more likely to guess that it could be a very rare timing circumstance which iam not good at explaining at.
But in the same Frame the Common Event would do some things and the Event004 also when clicked,
some Event commands need a Frame to get initialised, else they could be overwritten before they start. Cant say for sure which one it is in your case, but i remember running into something like that in the past. It could be solved. Hopefully i dont remember the wrong solution. But you could try this:

In Event 004 make your first Eventcommand be:
Eventcommand "Wait" and select 2 Frames. Than the rest of the Code as was.

Let us know if it worked.
This worked. Thanks so much! I would never have known events need a frame to initialize. Thank you.
They do not need a Frame to get initialised. Only some commands like Moveroute, Sound Effect...
Normaly this is never needed in RPG Maker, it is only in this special case.
So i guess you will not need it again.

Common Events are executed first if i remember correctly, the Moveroute is given, than the Action Button triggers your Event 004
a Map Event, i believe this cancels the previous given moveroute somehow because both is happening in the same Frame, and while that player triggered Event runs, other Events are not executed if there are no Waits.(If i recall correctly, just comming back from a long Break) The 2 Frame Wait allows
that your common Event is checked again and will now execute, than in the 3rd frame the Eventcode in your Event 004 Continues. But withcorrect Moveroute from Common Event. 60 Frames = 1 Second.
Iam terrible at explaining complicated stuff i dont fully understand XD.

Iam glad to hear that it worked.

Edit: I believe i can explain easier.
CE - Gives Player Moveroute A.
Ev04 - Triggered by Action Button in the Same Frame, i guess the cause for Moveroute A to be overwritten.

The Wait in Ev04 allows the CE to run again and to Give the correct Moveroute A again.
Than Ev04 continues but the CE was able to give the correct Moveroute.

:MV3:
They do not need a Frame to get initialised. Only some commands like Moveroute, Sound Effect...
Normaly this is never needed in RPG Maker, it is only in this special case.
So i guess you will not need it again.

Common Events are executed first if i remember correctly, the Moveroute is given, than the Action Button triggers your Event 004
a Map Event, i believe this cancels the previous given moveroute somehow because both is happening in the same Frame, and while that player triggered Event runs, other Events are not executed if there are no Waits.(If i recall correctly, just comming back from a long Break) The 2 Frame Wait allows
that your common Event is checked again and will now execute, than in the 3rd frame the Eventcode in your Event 004 Continues. But withcorrect Moveroute from Common Event. 60 Frames = 1 Second.
Iam terrible at explaining complicated stuff i dont fully understand XD.

Iam glad to hear that it worked.

Edit: I believe i can explain easier.
CE - Gives Player Moveroute A.
Ev04 - Triggered by Action Button in the Same Frame, i guess the cause for Moveroute A to be overwritten.

The Wait in Ev04 allows the CE to run again and to Give the correct Moveroute A again.
Than Ev04 continues but the CE was able to give the correct Moveroute.

:MV3:
Thank you. I will use this to fine-tune this process. Much appreciated.
Oh...I think maybe I see what's happening.
Spoiler: theory
The map updates in this order each frame (cf Scene_Map#updateMain):
  • Main interpreter (current event);
  • Map events (move routes, Autorun/Event Touch triggers, update parallel events, ...);
  • Parallel common events;
  • Player (move by input, Touch/Action Button triggers, ...).
So, in your situation:
  • The "Sword Use" common event (Parallel) triggers first.
  • "EV004" (Action Button) would trigger after, during the player update cycle.
Parallel events start as soon as they trigger. In your original setup, it starts, then immediately assigns a move route to the player. As noted earlier, normal player input responses are suppressed during a player move route, so this blocks the action button trigger during the player update cycle.

By adding Wait 1 frame at the start of your Parallel event like Bex suggested, you allow the action button trigger to function as normal during the player update cycle.

However, I believe that would also allow for player input to be accepted for 1 frame. I.e. if a player happens to be standing still on a tile (i.e. not moving), then input a move direction and the action button in the same frame, they will do both: move, then swing. Unlikely, but not impossible; probably not a deal-breaker.

Original thread: https://forums.rpgmakerweb.com/threads/making-an-action-button-triggered-event-run-parallel.162665/