Wait for event completion after being forced to start from a parallel event

Hello everyone I need help to understand if the following event interaction can be fixed.

I have a parallel event which checks if in from of it there is an event, if so it forces it to trigger with the code:

$gameMap.event(Id).start()

(where Id is a game variable value of the event Id in front)

It works to trigger it but the problem is that it keeps triggering infinitely, because the conditions to trigger it (being in front of it) are there for many frames (seemingly forever). It's like the ok input is being kept forever in the stack and it keeps activating the event. I've tried to add wait some frames, or using self switches to stop it, but that won't work because I want the parallel event to stay as it is (in its direction mainly, but it might exist in all directions so 4 different directions) until the triggered action button event in front of it has finished its page event. I can't put some generic wait frames because I don't know how much time will take the triggered event, because this should work for any event. Furthermore I do not have enough selfswitches pages left on the parallel event to cover all directions and I don't want to add new plugin to add more pages.

My question is:
Is there a script code to put into a parallel event page (maybe in a conditional branch?) to make the parallel event to wait until the triggered event is done? Or at least cancel all the active inputs? Or at least make it wait a number of frames equal to the second event flow (but without knowing the time required from it) ?
I think you just need to add a second condition to make sure the event you want to trigger isn't already running.

You could turn a switch on or off.
Or you can use a conditional branch with a script line like:
$gameMap._events[36]._interpreter == null
which should evaluate true or false, if event 36 is active or not.
Hi there!

You can just use a regular switch or variable after you started the event.

If switch ID is off, activate the event and turn the switch on.
Else
Do nothing
I think you just need to add a second condition to make sure the event you want to trigger isn't already running.

You could turn a switch on or off.
Or you can use a conditional branch with a script line like:
$gameMap._events[36]._interpreter == null
which should evaluate true or false, if event 36 is active or not.
This is what I was looking for! Gonna try in minutes and let you know by EDIT.

Hi there!

You can just use a regular switch or variable after you started the event.

If switch ID is off, activate the event and turn the switch on.
Else
Do nothing
Unfortunately not, this won't work, because there will be multiple events that I can't create a switch for everyone of them. Alternatively I could trigger a self switch to that event and check if its self switch is true/false. However this could lead to potentially harm situation if the triggered event becomes a parallel one and so on, plus it is a more time-consuming solution!

Guess to check the

$gameMap._events[36]._interpreter == null

situation is way smoother! Thank you both for the ideas and help.
I think you just need to add a second condition to make sure the event you want to trigger isn't already running.

You could turn a switch on or off.
Or you can use a conditional branch with a script line like:
$gameMap._events[36]._interpreter == null
which should evaluate true or false, if event 36 is active or not.
I recommend not to check if something is null, because it could also be "undefined" In JavaScript. I suggest to use this line !$gameMap._events[36]._interpreter
Tried with both solution, it seems the parallel event won't stop triggering the other event, but I found why! Indeed it works with events without text or dialogues.

It's because the event triggered has a dialogue text so you must push "ok" or "enter" to close it and that triggers the parallel event again. In this way, what's need is not a check of "if the event is still running" but more a "input cleaner from memory"... can't think of a viable and easy solution 🙁
How about a workaround attempt?

In your Parallel Event:

If your Condition is true, do not call the common event. but do:

If your Condition is true, do:
If Switch1 is Off? If yes do turn switch1 to On
Call your Common Event. (Thatway it is executed only one time)

At the end of your Cutscene Event, turn the Switch Off again.

You can reuse the same Switch for every event on every Map.
Because it can be only one of these Events infront of the Player at a certain time.
How about a workaround attempt?

In your Parallel Event:

If your Condition is true, do not call the common event. but do:

If your Condition is true, do:
If Switch1 is Off? If yes do turn switch1 to On
Call your Common Event.

At the end of your Cutscene Event, turn the Switch Off again.

You can reuse the same Switch for every event on every Map.
Because it can be only one of these Events infront of the Player at a certain time.
Thank you for your suggestions, however that won't work either. This is because the problem is that the dialogue ending input (ok or enter input) is the same triggering the event with that dialogue. I've partially solved this iteration by putting a dialogue text halt within the text, but now the dialogue shows and cancels automatically, without waiting for the player input. Instead, I'd like that the player can input the dialogue shut down but avoid to trigger again the parallel event condition "check if enter/on input is pressed". I've tried to swap that with long imput condition, but that feels too mechanical!

I would need something like:

"if (conditions are met) then
if ok/enter input is pressed
force event (id)
cycle
wait for event (id) to finish
if event (id) is finished
break loop"

Don't know if it's the smartest structure however the concept is that the "check if the event is finished" and "force event" command must both stay within that parallel event itself when condition are met.

It's a spawned event within a complex iteration so it's better if it works itself alone autonomously.
That sounds very strange to me, are you using some kind of button plugin to call common events?

because my example was:

If your Condition (Edit: OK Button being pressed) is true, do:
If Switch1 is Off? If yes do turn switch1 to On
Call your Common Event. (Thatway it is executed only one time)

That means you should have no ok button problem anymore. Did you test it? Could you show a Picture of the Eventcode?

Edit: Sorrry i did not understand the problem fully at first, try the below:
In case of ok button problem try this after your last textbox in your event cutscene:

Last Textbox
----------------
Loop
If Button Ok is pressed
if yes Wait 1 Frame
else break Loop
----------------
Turn Switch Off

Thatway the Cutscene Event waits until the Player has released the Ok button after the last textbox,
only than the switch is turned off again. That should prevent the retriggering when closing the Textbox with ok button.
That sounds very strange to me, are you using some kind of button plugin to call common events?

because my example was:

If your Condition (Edit: OK Button being pressed) is true, do:
If Switch1 is Off? If yes do turn switch1 to On
Call your Common Event. (Thatway it is executed only one time)

That means you should have no ok button problem anymore. Did you test it? Could you show a Picture of the Eventcode?
it does not call a common event but an event on map. That won't change anyway the problem, because whether it is a common event or a map event the true problem at the core is:

there is a parallel event checking constantly if Ok/enter input is pressed

if it is pressed, another event opens a text window message.

that text window message requires the player to press ok/enter to close the text window message

then parallel reacts and trigger the event and the message again

so the infinite loop is
parallel event - > if ok is pressed - - > map/common event - > open window || ok is pressed || parallel triggers again
I was half asleep and half missunderstood at first. Sorry for that.
I Edited a Solution for your Last Textbox and the Ok Button Problem.
See above. I hope it helps.
Unfortunately it doesn't work. I will write here the whole parallel process logic:

Code:
if 'cancel input' is pressed
 this event self switch A ON (the A page is a auto-cancel)  
else
  if 'up button' is pressed
  this move up
  else
    if 'left button' is pressed
    this move left
    else
      if 'right button' is pressed
      this move right
      else
        if 'down button' is pressed
        this move down
        else
        if 'ok button' is pressed
           if switch 01 is ON
           wait 1 frame
           else
           Script:$gameMap.event(1).start(); // event 01 will open a text window of a dialogue
           wait 5 frames
        else
        switch 01 = OFF
      end
     end
    end
  end
 end
end

even if I add your portion, that won't change the reiteration of the trigger unless locking the parallel event but I don't want to lock it 🙁
Seems like the easiest fix would be to have your parallel event trigger off a different button, like Shift or something.

Failing that, maybe you could try having it work off of "Button Triggered" instead of "Button Pressed"?

Like, have your script be:
if (Input.isTriggered('ok')) {$gameMap.event(1).start();}

Does that work? I guess it might be finicky about having to hit the check at exactly the right frame...

Well, I tried it out and it works a little better; it doesn't work if you tap OK to clear the text box, but it works if you hold it for a short while. Not ideal though.
yes I've tried this solution however it won't solve the perpetual OK check one for all!
🙁

The perfect solution would be something like:

trigger dialogue - > then a script in a conditional branch that tells (i can put it as first conditional branch so it's the first thing checked)

if a dialogue window is ongoing: nothing
else
back to parallel

EDIT: I've solved with a conditional branch at the very beginning and using
if Input.isTriggered(ok)
while on the trigger the dialogue input i've chosen --> Input.isPressed(ok)
So, it seems like you only want it to do something if enter is pressed while no event is running? Then something like that could work.

If enter is pressed and self switch A is off:
- Set self switch A on
- If there's an event we can run then run it

If enter is not pressed:
- Set self switch A off

That should trigger only if enter starts being pressed while no event is running.

A more reliable way might be to make a plugin to modify the update function or use onKeyDown to react immediately after a key is pressed.

EDIT: Just noticed your edit: doesn't this require you to run the parallel event every frame (without wait commands)?
So, it seems like you only want it to do something if enter is pressed while no event is running? Then something like that could work.

If enter is pressed and self switch A is off:
- Set self switch A on
- If there's an event we can run then run it

If enter is not pressed:
- Set self switch A off

That should trigger only if enter starts being pressed while no event is running.

A more reliable way might be to make a plugin to modify the update function or use onKeyDown to react immediately after a key is pressed.

EDIT: Just noticed your edit: doesn't this require you to run the parallel event every frame (without wait commands)?
The self switch thing won't work because it's an event already on self switch A. For i need it to keep its directionon the sprite, the remaining switches B, C, D won't cover all Directions. Yes I could just use a regular switch for the 4th one, yet it was not the smartest solution but a grinding one. However I've solved by enclosing the existing event within a macro

if input is triggered then

else nothing



this way, the logic becomes:

check if ok input (triggered)
check if an event is ongoing
check for any directional keys and move
check if an event is before the event
check if switch 01 is on
check if ok input (pressed)
switch 01 ON


then in another parallel common event activating with switch 01 I've put just the commands
execute event in front
and
switch 01 off


Yes everything without waiting any frame, so when the event is forced, being the last condition, the parallel event goes then back at the start and won't do anything if ok is pressed neither if an event is ongoing... sorry for the stupid question it was probably easy but the giant sequence of if and elses got me confused 🙂
The self switch thing won't work because it's an event already on self switch A. For i need it to keep its directionon the sprite, the remaining switches B, C, D won't cover all Directions. Yes I could just use a regular switch for the 4th one, yet it was not the smartest solution but a grinding one. However I've solved by enclosing the existing event within a macro

if input is triggered then

else nothing



this way, the logic becomes:

check if ok input (triggered)
check if an event is ongoing
check for any directional keys and move
check if an event is before the event
check if switch 01 is on
check if ok input (pressed)
switch 01 ON


then in another parallel common event activating with switch 01 I've put just the commands
execute event in front
and
switch 01 off


Yes everything without waiting any frame, so when the event is forced, being the last condition, the parallel event goes then back at the start and won't do anything if ok is pressed neither if an event is ongoing... sorry for the stupid question it was probably easy but the giant sequence of if and elses got me confused 🙂
Well, I guess that's one way to do it. Just be careful with parallel events that don't do any waiting and execute every frame: if you have more of them they can tank your performance quite fast.
Well, I guess that's one way to do it. Just be careful with parallel events that don't do any waiting and execute every frame: if you have more of them they can tank your performance quite fast.
yup! however that's an exclusive one: when you use it, it's the only ongoing stuff!
I found a possible solution puzzle peace in the RMMV Scriptcall list.

Use Eventcommand Script on Page3:

this.setWaitMode('message');

No matter which NPC i talked to, my one parallel Event would Stop until the Textbox gets closed.
that was what I was searching for! Thank you I'll try to use this because it's more optimized

Original thread: https://forums.rpgmakerweb.com/threads/wait-for-event-completion-after-being-forced-to-start-from-a-parallel-event.154267/