Create a loop that runs in the Background

I want to create a loop that runs in the background, so that other processes are not affected.

In my case I've replaced the default ingame menu with a picture based menu.
Issue is: I want the background image of this menu to change after a few seconds.

Problem: Currently I can get the changing BG image working, but then I can't use the functionality of the menu anymore, because the loop for the changing BG image is still running. And when I break the loop I can use the menu, but the BG image does not change anymore. Is there a way to make the changing BG image somehow in the background, so it does not wait for this loop to be finished?

I hope I was able to make clear what I mean ^^'
Have the BG change be a parallel process. A common event that can be turned on and off with a switch.
hm, how do I do this exactly?
I'm not an expert in event scripting. I've just recently started with eventing and created some events with the help of some tutorials that I adjusted a bit to my liking.

I've tried different ways, but was not able to get this to work. My most recent try is this:

The CommonEvent for the menu that replaces the standard ingame menu (in combination with a local event on each map). Before I had the comment as a script instead of the Control Switch #0002 and the Common Event call. This was workung just fine, but thw BG image was not changing.
imagechange1.png


The new Common Event for the image change. To keep it simple for the test, I just use 2 images at the moment that change every 5 seconds.
imagechange2.png


The Problem:
Well, the image change loop works, but the loop already starts when I open the map. The "MenuBG" and "MenuBGglitch" change every 5 seconds, but I can't do anything anymore.
The newMenuImgChange event is triggered as soon as the switch #2 is on.
You don't need to use the [call common event] command after the [control switch] command.
If the event is running as soon as you enter the map then you might have switched #2 ON in another event somewhere.

You don't need to loop within a parallel process because it'll cycle back to the beginning after the last event command.
However, when you use [call common event], the event process only runs once. Which is probably why you're using the loop.

I believe what you have here are 2 processes of the same event running (newMenuImgChange). 1 was triggered by switch#2 and the 2nd from the [Call Common Event]. They're both showing and erasing Picture 1 in near synchronization.

MenuBG and MenuBGglitch are both picture #1. The Erase Picture #1 command isn't necessary because you're just replacing the img of picture #1 with another. If it helps, think of it as a picture frame.
You only need to get rid of Picture frame 1 when you close the menu.
Just to add one thing on top of coyotecraft's response, both of your top two lines are unnecessary.

You start with a conditional "IsNewMenuOpened ON?" but that's the switch that activates the event in the upper right corner. It's impossible for this event to be running if that switch is off.

Then, as pointed out, the loop is unnecessary because both autorun and parallel events already loop. If you want it to stop running, you turn off the switch that activates it.
thank you both 🙂
I just deleted the first two lines because youre right, they were like doubled 😀

I still don't know exactly why the newMenuImgChange is running everytime automatically when I enter a map (because the switch #0002 IsNewMenuOpened? is only turned on when you press escape and enter the newMenu, and is turned off once you leave the menu again). When the newMenu is opened, its the only time the switch #0002 IsNewMenuOpened? gets turned on. Nowhere else.

But well, I have a local event on every map when you enter it and I just added there
1681246674421.png

So the switch gets manually turned off on every map at start.

I really still don't know why it seems to be on by default, but at least the result is now as intended ^^'
If you go to Tools > Event Searcher , you can search for an event that uses Switch #2.
Since it's such a low number, my guess is that you were experimenting early on and forgot to delete it.
Hmmm...
when I use the event searcher to look for switch #2, I get only 2 results:
index.php



The first is the local event on the map 002 that disables the standard menu, where I just added the last line to turn the switch #2 off a few minutes before. (Tbh, with my current knowledge I don't really understand why there has to be a self switch that is turned on, this part I followed blindly from the tutorial for a basic image based menu)
1681247983997.png
1681248013280.png



The second is the common event for the newMenu. Maybe I did something wrong here.
I have here the entire event code (split in two parts so its better readable). I've just darkened the areas that only say what image to show or what BG music to play, so we can focus easier on the important stuff. You open the image based menu by pressing [ESC], and you can leave it by pressing [ESC] again or by saving (after the saving it closes automatically too).
newMenuIssue.png
Are you using any plugins? The only other explanation I can think is a plugin that uses Switch2 for something and sets it ON by default.
That a good point. I try to use not more plugins than absolutely needed, but there are some that I need for some functions, but that I've not checked in detail yet. I will check this tomorrow and report back.

Original thread: https://forums.rpgmakerweb.com/threads/create-a-loop-that-runs-in-the-background.156563/