In an effort to keep learning, I am wondering if there is a way in JavaScript (not super complicated) to have a Wait that can also be interrupted by a condition.
For instance, I have Parallel Events that run continuously under certain conditions and the player can change the Wait time in these Parallel Events from 1 to 5 minutes. I use these for changing backgrounds, changing background music, and changing puzzle themes.
So if the player wants one of these things to change, the Parallel Event gets turned on and the BG, BGM, or Theme start to change based on whatever number of minutes the player chose.
But while that is running and happening, the player can change the number of Wait minutes. And I want that change to take effect BEFORE the full Wait time elapses. So if the player initially chose 5 minutes but then changed it to 2 minutes, I don't want the Wait to finish the full 5 minutes. I want it to get interrupted, to change whatever is being changed, and then start the new Wait time.
So I did a simple Wait Loop and inserted a Conditional Branch check to see if the Wait Loop needs to continue or if it has changed.
Here is what I did:
So in this example, the player set the change frequency to 5 minutes. The Parallel Event gets to this part and starts Looping. The Wait is 15 seconds, then it checks to see if the set number of Loops has passed (if so, then break the loop) and if not, then check to see if the change frequency amount was changed by the player.
And I can change the delay amount by decreasing the Wait frames. Right now it is 15 seconds. But I could lower that to 5 seconds and increase the Loop count.
For my Event, I can't just break the loop in that instance because then the game would automatically start another Wait instead of starting over from the beginning of the event. Which is why I have the Jump to Label (End) command.
So I am wondering if there is a way to do something like this with JavaScript that isn't incredibly complex.
I just tested the Wait script (this.wait($gameVariables.value(12))
;) which works fine with setting a Wait that is higher than what the default Wait Event Command will allow (999), but I couldn't figure out a way to break that Wait in the middle of waiting.
I could just turn the Parallel Event off and then on again, but that isn't ideal and causes an undesired effect in the game.
I tried searching for this in JavaScript resources, but didn't have much luck.
Thanks for any thoughts that you might have.