Randomizing the enemy that shows up

I'm trying to make a system where I have a variable randomizing from 1-100 in this case and with 4 different enemies spawning in the room you get in depending on that variable.

I'm having trouble getting the variable to run it once per monster battle and refresh after you win the battle.

Here's how things are programmed:
Randomizer:[ISPOILER]
1668479518481.png

1668479542832.png
1668479558515.png

[/ISPOILER]
The Conditional:
[ISPOILER]
1668479697709.png

1668479717067.png

[/ISPOILER]
And how the enemies are programmed:
[ISPOILER]
1668479797008.png

[/ISPOILER]
All monsters have the same lines with only their respective variables changing accordingly.
I'm confused about your first picture, event 4.

You have "randomize the variable" in a loop...that never has a break command to stop the loop.

It's never going to turn on Self Switch A because it's never going to stop making your variable number as fast as the game interpreter or your processor will let it.

What are you intending to accomplish there?

And why would you have the code that looks at that variable and determines the monster pages be in a separate event?
I'm confused about your first picture, event 4.

You have "randomize the variable" in a loop...that never has a break command to stop the loop.

It's never going to turn on Self Switch A because it's never going to stop making your variable number as fast as the game interpreter or your processor will let it.

What are you intending to accomplish there?

And why would you have the code that looks at that variable and determines the monster pages be in a separate event?
I initially had it outside of a loop, but it would only run once, even after defeating a monster. In the loop it keeps randomizing. I would like it to randomize once every time a battle is done.

Love your pfp btw 😀

Wouldn't it be easier to just make each of the monster events have a first page that autoruns, randomly determines what it will be, and set a self switch to go to that page? Then you can copy code to each section of the battle processing events to turn off all of those self switches so they re-randomize when you get back to the map.
I'll try that!
Just because you seem to have been typing your response while I edited my original reply 😛 It's unnecessary/not a good idea to have the event that sets your monster event switches be a different event from the one that's randomizing.

If you make the event Autorun/Parallel and it consists of
Randomize Variable
Do the conditionals to set one of the monster events based on the variable value
Erase Event

it will run one time every time the map loads.
If you make the event Autorun/Parallel and it consists of
Randomize Variable
Do the conditionals to set one of the monster events based on the variable value
Erase Event

it will run one time every time the map loads.
Would I make it all one page with all the conditionals for all the monsters or would it be one page of the conditional per monster?
If you have yanfly's plugins his SwapEnemies plugin does exactly what you're looking for with no programming. I use this and then a RNG to decide if their will be 2, 3, or 4 enemies encountered, and the SwapEnemies automatically randomizes the enemies from a pool you set. That way with like 5 minutes of programming I can make every encounter not only random in which monsters you fight from a pre determined list, but also randomize the amount of enemies there will be. In my case a heavy weighting for 3 enemies, and a lighter weighting for 2 or 4.
without plugin, you probably only need 1 event, 2-3 pages for the setup.
like ATT_Turan said, the loop is never going to break, and you use also
a bit to many unnecessary things you could avoid as well.

as I dont know the plugin KawaiiKid mentioned, it should be best to look
into it or a tutorial to see if it's something you can use (if you dont own it).
Would I make it all one page with all the conditionals for all the monsters or would it be one page of the conditional per monster?
I don't see why you would need multiple pages. Structure exactly as I typed in my last post - what part of that needs a separate page?

I'm not asking that in a snarky-teach-you kind of way, it's possible I'm missing something in your logic. But it looks to me like you are setting one variable to a value and then doing one thing with that variable (within a nest of conditionals).

Pages are primarily for map events that need either different graphics or different triggers under certain circumstances. If that's not the case, generally the only reason to use pages is if you manage to meet the limit on event commands on a single page.

Your code doesn't appear to meet either criterion. As a general rule, do not break up your code any more than you have to. Use one page when you can, use one event when you can.

If you have yanfly's plugins his SwapEnemies plugin does exactly what you're looking for with no programming.
Swap Enemies functions at the Troop level once battle has started. The OP is using events on the map with graphics representing what kind of enemy they will be - this plugin can't help with that.

If the OP were okay with using a generic monster image, then Swap Enemies could randomize the monster once battle started, but that's not the setup shown in the screenshots above.
I went on to boot my RPG Maker MV to test that, but now it's just not booting Sometimes it starts for a few seconds then crash and close immediately. 😢
I don't see why you would need multiple pages. Structure exactly as I typed in my last post - what part of that needs a separate page?
No snark taken, I'm just clueless when it comes to programming errors. I just wanna make sure everything is programmed properly.
Had to restart the whole thing in a different computer, here's how its looking. The whole event doesn't fit in the screenshot but its only cutting off the Erase Event at the bottom.

That being said I still run into the issue I had previously. I have a command to show the variable once I enter the room and it doesn't match the enemy. (i.e. I got a "9" show up and a Slime spawn).

Should I nest all the if statements? or put them under as Else statements? I don't know what else to do...
Screen Shot 2022-11-16 at 1.17.35 PM.png
That being said I still run into the issue I had previously. I have a command to show the variable once I enter the room and it doesn't match the enemy. (i.e. I got a "9" show up and a Slime spawn).

Should I nest all the if statements? or put them under as Else statements?
You would have to show the pages for the event that showed up as a slime, because there must be an error there.

This looks fine.
They all follow this same pattern:
Screen Shot 2022-11-16 at 9.09.30 PM.png
Screen Shot 2022-11-16 at 9.09.49 PM.png


Which is pretty similar to what I had initially. I also tested the command that shows the random variable and with that set up it really only brings a different number when you leave and enter the room. So unlike before, the number should correspond to the enemy's switch.
They all follow this same pattern:
...well, you need to check them again. Just from the two pages of the one event you posted, I can see the Slime page still has Switch Bat as the condition...which is exactly what you described in your prior post.
Oh duh... Thank you, I was just all over the place with my RPG Maker not booting up that I must've overlooked that.

Original thread: https://forums.rpgmakerweb.com/threads/randomizing-the-enemy-that-shows-up.152687/