Help: My event script keeps repeating and I'm not sure why!

I'm trying to make a system in which each "day" 1 randomly picked event of 7 is chosen and applied to the game. I also wanted to set it so that if a chosen event is picked 5 time or more it'll instead keeping choosing till it chooses something else. IE. if it's been foggy for 5 days and it picks fog again it'll keep rolling until it gets something that isn't fog. This applies to enemy and ally smoke and gas attacks and so it'll roll again if either have hit the 5 day limit and has picked either sides gas and smoke attacks again (2,3 and 4,5) respectively. Again I'm aiming to limit every event to a max of 5 days in a row and to pick another event if it picks those events.

So, I have copied this format 7 times, each corresponding to a "world event" (enemy smoke screen , ally smoke screen , Enemy poison Shelling , Ally poison Shelling , Fog , rain ,normal) Problem happens on the third "Event" generation, usually it gets poison gas and the text begins to keep looping "the enemy( or ally) is gassing the battlefield" But after going through my event scripting I can't for the life of me figure out why. Thanks in advance for the help!

I think it has something to do with the loop event since I'm not quite sure how to use it properly yet!


[Edit] adding more pictures to show easier [Edit]
1617037406627.png
1617037428035.png
1617037443684.png
1617037460060.png
1617037474489.png
1617037492021.png
1617037503102.png
1617037515892.png
1617037527091.png

[EDIT4] I THINK we've solved this issue, hard to tell with the way the system works but testing has shown promising results! Thanks again everyone for the amazing help!

[EDIT3] I've also ran into a issue where when I call common events (rain,fog,gas,ect) the rain event's weather event doesn't disable even though the other common events disable weather effects, not sure what I'm missing on this one!
1617094607788.png
1617094624155.png

Here's two events to compare, rain and enemy smoke respectively. I added this problem to the main post since I figured it had to do with the system as a whole but if not lemme know and I'll happily delete it! (Still not quite sure what double posting is but I'll try my best not to break any more rules!)
You're only showing part of the event, which makes it hard to tell. But it's probably got something to do with your resetting the same variable that you're randomizing, and then checking it again.

Maybe show the whole event so we can get a better picture? And for at least one of them, show the whole event window - can't even tell if that's a map event or a common event, what the trigger is, whether you have an all-encompassing loop, and whether there's a conditioning switch, or what happens outside of the condition you show on the top row. All of that is important, and any of them could affect your event. It's going to take a few pages, but better to show it so we can see it all.
You're only showing part of the event, which makes it hard to tell. But it's probably got something to do with your resetting the same variable that you're randomizing, and then checking it again.

Maybe show the whole event so we can get a better picture? And for at least one of them, show the whole event window - can't even tell if that's a map event or a common event, what the trigger is, whether you have an all-encompassing loop, and whether there's a conditioning switch, or what happens outside of the condition you show on the top row. All of that is important, and any of them could affect your event. It's going to take a few pages, but better to show it so we can see it all.
Of course! My bad I'm new to this kinda stuff! I'll be sure to edit in pictures of the rest of the event as soon as I can! Sorry about that!
Th
You're only showing part of the event, which makes it hard to tell. But it's probably got something to do with your resetting the same variable that you're randomizing, and then checking it again.

Maybe show the whole event so we can get a better picture? And for at least one of them, show the whole event window - can't even tell if that's a map event or a common event, what the trigger is, whether you have an all-encompassing loop, and whether there's a conditioning switch, or what happens outside of the condition you show on the top row. All of that is important, and any of them could affect your event. It's going to take a few pages, but better to show it so we can see it all.
again, thanks for heads up! I added all the images that might be important! hopefully this'll make the issue easier to fix!
Okay, so there are a few things in here. For one thing, some of your loops will never happen.

Look at your conditional starting with weather choice equals 2 (leads to enemies soaking the battlefield). The first thing you check inside the loop there is if weather choice doesn't equal 3 - well, you got there from weather choice equalling 2, so this will always automatically be true and break your loop.

The same is true in the loop that you're getting stuck in - you ask is weather choice equal to 4, then your first condition in the loop says if weather choice isn't equal to 5, break the loop. That means once weather choice is 4, nothing will ever change it.

Next, it looks like you're controlling the entire event with the new day variable, but it looks like your entire section from weather choice is 4 down is outside of that conditional - I think you want to cut from there to the bottom of your event and paste that above the last End before it.

You could also remove that conditional from your event and simply make the New Day switch be a condition on the left hand side of the event window. That means the parallel event won't be running every frame checking for the switch to be on.
AWESOME! Thanks a million! Would swapping the weather choice not equal conditionals fix the issue? I'm worried that since both 4 and 5 are technically the same thing it'll just switch between enemy poison gas to ally poison gas and back. Thanks again for amazing help!
If you don't want to have 4 or 5 happen in a row, the best way to do that is to change the conditional inside of the loop to be a script line that checks both possibilities at once:
Code:
if ($gameVariables.value(2)!=4 && $gameVariables.value(2)!=5)
so that way you'll loop, assigning variable 2 a random value until it is neither 4 nor 5. And you'd put that inside both loops.

But also double check the other part I said - click on the If at the very top of the event, see if the highlighted portion ends before weather choice 4.
If you don't want to have 4 or 5 happen in a row, the best way to do that is to change the conditional inside of the loop to be a script line that checks both possibilities at once:
Code:
if ($gameVariables.value(2)!=4 && $gameVariables.value(2)!=5)
so that way you'll loop, assigning variable 2 a random value until it is neither 4 nor 5. And you'd put that inside both loops.

But also double check the other part I said - click on the If at the very top of the event, see if the highlighted portion ends before weather choice 4.
I switched the event page to turn on when new day switch is on, so the new day switch at the top is gone! sorry about that I changed it up right before I read your reply. But I'm think it was outside the conditional like ya said!
Last question! It calls for common events when it's corresponding number is picked, problem is when rain is picked the rain effect stays even after switching to other common events. I've set all other events to set the weather effect to none but it doesn't seem to stop the rain effect. Wondering why it won't disable the rain effect!
I don't think we have any way to know how you're making your rain effect or what is inside of the common event you're using to start it.
Have you tried to do a "wait 20" after disabling the rain effects?
That sometimes helps.
I don't think we have any way to know how you're making your rain effect or what is inside of the common event you're using to start it.
Shoot, my bad! I keep forgetting to send pictures!
here's the rain common event I set up
1617052127214.png

And here's a another common event, I made sure the rest would turn weather effects off in their contents but it doesn't seem to change anything.
1617052194829.png

I was hoping that if it sets weather effect to none it would disable the previous common event's effects (rain's effects and visuals would be cancelled out by the poison gas's effects and visuals).
Jus t
Have you tried to do a "wait 20" after disabling the rain effects?
That sometimes helps.
tired like ya recommended and it seems to have had no effect sadly! thanks for the suggestion though! I never would have tried originally!
Do you know that second event is happening? The screen tint and party states are being applied, but the weather isn't changing? There's no reason to put a wait command in.
Double-post notice: @potato1448

You can use the +Quote button to quote multiple people, or just tag them instead of quoting them.

I haven't had time to look through your screenshots, but I have a feeling that whole big list can probably be reduced to just a screen or two. I'll take a look after work and see if I can help you simplify it, and solve the other issue as well, if someone doesn't help you resolve it in the meantime.
Gotcha! Thanks a million for the help! It's greatly appreciated!
Alright, I have only had a very quick look at your screenshots, but I think you are taking the super long way about it.

I notice your logic is in a map event. What is meant to happen if you're on a map then the day changes? Should the weather on the map change then and there? Or do you have something set up so the day only changes when you go from one map to another?

Here's what I would do ...

Set the event to parallel process, and add the Switch 1 New Day is ON as an event condition (above the section where the sprite would go), not in the event commands. This means it's only going to run when it needs to. Your current method has it running the entire time you're on the map, checking and looping, which can cause lag. The following method uses 3 variables and no more. It also uses one common event, which decides for itself what weather to show - this means you don't have to add all of those common event calls on every map and hope you've got it right.

Code:
Label: Random Weather
Control Variables: 2 Weather Choice = Random Number between 1 and 6
Conditional Branch: Variable 2 Weather Choice <> Variable 3 Last Weather
  Control Variables: 3 Last Weather = Variable 2 Weather Choice
  Control Variables: 4 Same Weather Days = 1
  Common Event: Change Weather
Else
  Conditional Branch: Variable 4 Same Weather Days < 5
    Control Variables: 4 Same Weather Days += 1
  Else
    Jump to Label: Random Weather
  End
End
Control Switches: 1 New Day = OFF

That's it. That's the whole event.

It has a variable to determine what today's weather will be (2), a variable to keep track of what yesterday's weather was (3) and a variable to keep track of how many days the weather has remained unchanged.

If the new weather is different to yesterday's, it starts to track all over again and calls the CE to change the weather. If the new weather is the same as yesterday's, it checks how many days it's been like that, and if it's been less than 5 days it just updates the number of days (no need to change the weather 'cause it's already correct). If it's already been 5 days, it goes back to the start and chooses again.

Now, for your weather, I would put the whole thing into just one common event like this:
Code:
<Comment> Enemy Smoke
Conditional Branch: Variable 2 Weather Choice = 1
  ... do whatever is needed for enemy smoke
End
<Comment> Ally Smoke
Conditional Branch: Variable 2 Weather Choice = 2
... do whatever is needed for ally smoke
End
<Comment> Enemy Gas
Conditional Branch: Variable 2 Weather Choice = 3
  ... do whatever is needed for enemy gas
End
... and so on

For each one, make sure you UNdo all of the other weather types. If you're not sure if it's working correctly, put a Show Text \V[2] as the very first line of your common event, so you know what weather it SHOULD be making. If it's still not working, check all of your plugins and make sure none of them have variables and are using variable 2 by default. That happens VERY often because people just add plugins and don't read through all the documentation or check all the parameters.

Hope this helps.

Note - when you reply to me, please do not hit the reply button on my post. Quoting everyone makes it much harder to read. Just reply without quoting. Tag me if you need me to know that you've replied.
Rad! it's all working! Thanks again for the amazing help! Couldn't have done it without everyone's suggestions!
Thread closed

Original thread: https://forums.rpgmakerweb.com/threads/help-my-event-script-keeps-repeating-and-im-not-sure-why.134877/