MV (Likely advanced) How do I make a parallel process' random variable event happen only once after button press?

Please read the entire post, as the problem is not as simple as the title may suggest.

Post summary
My game contains random encounters/loot drops upon the press of a button that calls a common event. Inside this common event "Forward Button" is a conditional branch for if the Switch "skip random encounters" is OFF, and inside it another conditional branch for if the Switch "random encounters" is ON, which then calls for the common event "Random Encounters". Despite the fact every random battle/loot drop turns "skip random encounters" ON, there is a chance for the player to be stuck in an infinite loop of battle/loot calls, where they cannot press "Forward" or "Backwards" again.

I have recently completed a game; it does not possess field exploration. There is only a single screen, and the player may press either a "Forward" or "Backwards" button.
Screenshot_13.png

The buttons were achieved by the use of YEP's Picture Common Events.
This is the current common event for the Foward button.
Illustration2.png

A press of the Forward button is supposed to increase the invisible Cnt. event by 1, and the visible Turn counter (Cnt. turn) and Step counter (Cnt. step) by 1, while decreasing the visible Energy (Cnt. Fatigue) by 1. After waiting 5 frames it turns the Switch "random encounters" ON. If the Switch "skip random encounters" is OFF, it calls upon what the Switch "random encounters" does: calling the Common Event "Random encounters."

The "Random encounters" Common Event is too long to post fully, but here is an average call.
Illustration4.png

"If cnt. turn is equal or above 9" -> flexibility to have multiple different batches of random encounters possible as the turn counter increases.
Control variable "random event" from 1 to 10 -> Numbers 1, 4 and 7 include random battles. 9 and 10 random loot drops.
There are multiple conditional branches for the numbers 1, 4, 7, 9 and 10, nested in ascending order (1 first, 10 last, while skipping unused numbers) inside else statements.
The Common Event "loot processor" was evented in the same way as the "random encounters" Common Event, instead distributing randomized items as opposed to battles.

Additionally, within the map where single-screen exploration occurs, there is a paralllel process event that checks for the invisible "cnt. event", dictating whether a random encounter is absolutely unable to happen because a cutscene should play instead. I don't believe it's causing the problem, but it may be useful to show as well.
Screenshot_1.png


The problem
Something about the way all of these were evented in conjunction makes it so the player is able to become stuck in a loop of endless battles/loot drops, unable to press the Forward or Backwards buttons ever again. I need a solution to make it so these calls for random battles and loot drops are only able to happen once per press of the Forward button.
Is anyone able to help?
So you have an image on screen, that when clicked on triggers a common event ("Forward Button") using Yanfly's Picture Common Events. That event triggers another common event ("Random encounters"). That event will then trigger other common events, not shown, such as "Battle exit" or "Fatigue loss". But after those are done, the "Random encounters" event loops and plays again, getting the player stuck? Is that what you're saying?

You say in the title about a "parallel process", but you haven't shown any parallel events, except for the "Event processing" which you didn't think was an issue. Unless "Random encounters" is set to parallel?
So you have an image on screen, that when clicked on triggers a common event ("Forward Button") using Yanfly's Picture Common Events. That event triggers another common event ("Random encounters"). That event will then trigger other common events, not shown, such as "Battle exit" or "Fatigue loss". But after those are done, the "Random encounters" event loops and plays again, getting the player stuck? Is that what you're saying?

You say in the title about a "parallel process", but you haven't shown any parallel events, except for the "Event processing" which you didn't think was an issue. Unless "Random encounters" is set to parallel?
Hm... I may have misspoken when it comes to the problem, in the title, but I think the post might be enough to understand what it actually is. Still apologies for the confusion.

I don't believe Battle exit or Fatigue loss are the problem either, so I thought it wasn't necessary to show them. Battle exit causes a purely visual effect (where a fake text box slides into screen) while Fatigue loss a customized game over message.

After a player goes into random battle or finds a random loot drop, it seems that the variable number from 1 to 10 gets called again, and if it lands on 1, 4, 7, 9 or 10, the player goes into battle/finds loot again, and this can repeat itself indefinitely until they land on a number that does nothing. I've confirmed several times this is not a mistake of me forgetting to turn the Switch "skip random encounters" back ON after these happen either.

So what I'm looking for is a way to event these so that these random encounters/loot drops only happen once until the player presses the "forward" button again.

edit: random encounters is not set to parallel, none of the common events are except for Fatigue loss (which triggers when cnt. fatigue reaches 0). That truly was a mistake on my part
Which condition type are you using for the Picture Common Event? I assume Click? I don't know exactly how the Yanfly plugin works, but I know I've have some odd behaviour before when I've used "TouchInput.isPressed()" instead of "TouchInput.isTriggered()" and the programme has fired my event 30 times because I held the mouse button down for half a second. But I don't think this could be the problem, unless you had it set to the "Repeat" type in the plugin parameters.

One way to try and debug it is to add some text boxes into your code just so you can see exactly which parts are actually running. Like, if you have a textbox somewhere in the Forward Button, just for testing purposes, you can see if it's running again, or if the game is just looping through the Random Encounters without going back to it.

Just one quick note, you turn rndm encounters on, and then immediately check to see if it's on. Is the idea that you're hoping the parallel event will turn it off in the brief period between those two instructions? That seems risky to hope for, without a wait to at least let the other event run a little. Otherwise, it seems pointless to check if rndm encounters is on, it always will be.
Which condition type are you using for the Picture Common Event? I assume Click? I don't know exactly how the Yanfly plugin works, but I know I've have some odd behaviour before when I've used "TouchInput.isPressed()" instead of "TouchInput.isTriggered()" and the programme has fired my event 30 times because I held the mouse button down for half a second. But I don't think this could be the problem, unless you had it set to the "Repeat" type in the plugin parameters.

One way to try and debug it is to add some text boxes into your code just so you can see exactly which parts are actually running. Like, if you have a textbox somewhere in the Forward Button, just for testing purposes, you can see if it's running again, or if the game is just looping through the Random Encounters without going back to it.

Just one quick note, you turn rndm encounters on, and then immediately check to see if it's on. Is the idea that you're hoping the parallel event will turn it off in the brief period between those two instructions? That seems risky to hope for, without a wait to at least let the other event run a little. Otherwise, it seems pointless to check if rndm encounters is on, it always will be.
I am using click. Ironically, my mouse has a problem with double clicking and after testing it several times just the other day I've discovered that the button being pressed multiple times or held is not the issue at all.

Adding text boxes to the forward Common Event told me that loops happened right after battle. So to see if it would help, I made the conditional branch for if rndm encounters was turned ON end in turning it back off and turning skip ran-enc ON, and moved the rndm encounters ON to right before the Wait 5 frames command, inside the forward Common Event.
Screenshot_3.png

Like so, and I still am facing the same issue, so it clearly isn't something in here. It definitely feels like I'm getting close to a solution, but I really just have no idea what's the main causer of the issue.
The weirdest part is that after all this testing, the repeated events can now only happen twice in a row at most. That's much better but well, still not fixed... 😅

I've also been able to strip the random encounter Common Event to its barest minimum, since the switches clearly weren't doing anything. Or maybe they could if I added something... it's quite tough to figure out.
Screenshot_4.png
Problem fixed.
I got some advice from someone else, and I don't know why I never thought of it but using "Exit Event Processing" at the end of battles/loot drops and making the random encounters not be called if a Switch is turned ON/OFF did the job. However thank you for your help also Showsni. :yhappy:
Screenshot_1.png
Screenshot_3.png

Original thread: https://forums.rpgmakerweb.com/threads/likely-advanced-how-do-i-make-a-parallel-process-random-variable-event-happen-only-once-after-button-press.178426/