Welcome, guideoui.com visitors. In this guide, We try to focus on RPG Maker MV How to Add Randomized Labyrinths Automatically Generated. While writing this guide, we pick up many pieces of information from several sites for you. We hope that this guide will help you.
Labyrinths are a fun way to keep the player engaged, however, they may prove to be too much work. If you wanted to make two 3×3 labyrinths you would need 18 maps! This guide about mechanics that can create random 3×3 labyrinths automatically using only two maps
How to Add Randomized Labyrinths Automatically Generated
In this guide we will make a “machine” that generates randomized labyrinths that though remain consistent until the player either solves them or forfeits them.
For this example we will always assume:
-all labyrinths will have a total of 9 rooms. (VroomTotal=9)
-all labyrinths will have the shape of a box. (VroomShape=1)
-the entrance is from the bottom of the box, into room 2. (Ventrance=2)
-the exit is towards the top of the box, out of room 8. (Vexit=8)
-the solution only needs you to traverse the labyrinth and find the exit, without needing to find any items or press any buttons
In order to better follow the logic draw a box of 9 squares on a paper and number them from 1 to 9, from bottom left to top right, so that room 4 is above room 1, etc. This way you will not get lost, especially in bigger labyrinths.
Note: Once you create this example in your game, you can play around with different shapes, entrances and exits. Everything is randomizable!
Create a simple square room with 4 exits: LEFT, RIGHT, UP, DOWN. Name it “Sample Room”.
This room will be our reference. This example will only use this room, but when you enhance your labyrinths you can use this as an example. Don’t make it complicated, don’t add columns and stuff like that. Just a simple room. This is the only room we need, however we will also make another one for simplicity’s sake.
Create a parallel event in “Sample Room”. This parallel event will have inside it a Common Event called “Rules”, a “FadeIn” command and the “Erase Event” command.
Create an empty map, without anything inside. Name it “Transitional”.
This room will be used only to ensure any parallel events in our Sample Room are restarted. When you become proficient with creating labyrinth machines, you will be able to bypass this room entirely, but for now we will need it.
Create a parallel event in “Transitional”.
This parallel event will have inside it a “Transfer Player” command, with our “Sample Room” as a map, and variables (VposX) and (VposY) as the coordinates.
Common Event “Creation”
Create a Common Event called “Creation”.
This will be called only ONCE per labyrinth, just before the player gets transfered inside the labyrinth. So, for example, as the player agrees to enter the labyrinth, the Common Event “Creation” will be called before the “Transfer Player” command.
Inside this event, put the variables we discussed in the introduction:
First Variables and Switches
So, forget about the “Creation” for now, we will come back to it whenever we want to add something to it. Now we have to make our first rules. For these we will need:
-Variable that holds the room we are currently in (VroomCurrent)
-Variable that tells the game the room we are heading towards (VroomTo)
-Switch that blocks the left exit (Switch LEFT)
-Switch that blocks the bottom exit (Switch DOWN)
-Switch that blocks the right exit (Switch RIGHT)
-Switch that blocks the top exit (Switch UP)
Before we do anything else, we already know where the player currently is in the beginning of the labyrinth.
They are at the entrance, right? Let’s pop this in “Creation” – it needs to be after Ventrance has been initialized.
Directional Switches and Events
Now, first of, let’s put the switches into place. Create an event for each one of the exits. Each of these four events must be:
-Trigger: Player Touch
-Create 2nd page
-Same as Characters
-Image: a boulder or a door or something that blocks movement
-Condition: Switch: one of the four directional switches we made, depending on where this exit is
For example the left exit’s 2nd page needs the switch “LEFT” as a condition. These 2nd pages will be activated when the exit is blocked. Later on we will see more of that. Remember that static images also need “direction fix” to be ticked, so that they don’t change shape when the character presses the action button on them.
Now, remember i told you to draw the box on a paper? Four things immediately come from that.
-Each room to the left is one number lower than the current room’s number
-Each room to the right is one number higher than the current room’s number
-Each room to the bottom is three numbers lower than the current room’s number
-Each room to the top is three numbers higher than the current room’s number
Now back to our exit events. So far we kept the first page blank since we didn’t have any rules. However now we have our first most basic rules. These are just directional so we won’t put them inside the Common Event “Rules”. Instead, we will put them right on the exits. When the player touches them, our machine needs to realize that the player is changing rooms, and where exactly is the player going.
-Left exit needs
Transfer Player to Transitional – wherever
“i” and “j” will need to be fine-tuned depending on the rooms you will be using. They are meant to give a sense of continuity to our labyrinth. In this room, they are the coordinates of the square in front of the right exit – since we are going left, we are entering the room from the right.
All other exits need the same things. The differences are the VroomTo subtraction or addition as well as the i and j values. So copy and paste these commands to all first pages of all directional events and change the VroomTo to:
-Right exit: VroomTo+=1
-Top exit: VroomTo+=3
-Bottom exit: VroomTo-=3
Now, we need a way to tell the machine that the room that the player will go to, is the room that the player is arriving in. This is why we have the Transitional map. Let’s go there and add this to its parallel event, before the Transfer Player command:
Now, when the player transitions, they will be transferred to the room they were heading towards.
We have now created a way to traverse the rooms while keeping track of where the player is inside the box! But right now it’s not that much of a box, right? Let’s fix that. And with this, we begin writing our first rules: Physical Limitations.
Let’s go to our Common Event called “Rules”. Before we do anything, we need to make sure that no switches will remain on or off from previous rooms, so let’s begin with a comment “RESET” and add our reset:
switches LEFT,RIGHT,DOWN,UP =false
Add a comment called “Physical Limitations” and let’s begin creating our box.
The physical limitations of a box are that you cannot exit its sides and corners. You can only exit through the entrance, forfeiting the labyrinth, and the exit, solving the labyrinth. See your paper? Now you can clearly see which directions must always be blocked, no matter how the labyrinth ends up like. So. Let’s do this:
If VroomCurrent=1, switches LEFT,DOWN =true (bottom left corner)
If VroomCurrent=3, switches RIGHT,DOWN =true (bottom right corner)
If VroomCurrent=7, switches LEFT,UP =true (top left corner)
If VroomCurrent=9, switches RIGHT,UP =true (top right corner)
If VroomCurrent=2, switch DOWN =true (bottom side)
If VroomCurrent=4, switch LEFT =true (left side)
If VroomCurrent=6, switch RIGHT =true (right side)
If VroomCurrent=8, switch UP =true (top side)
We also need to make sure the entrance and exit are definitely unblocked. Let’s add those:
If VroomCurrent=Ventrance, switch DOWN =false
If VroomCurrent=Vexit, switch UP =false
Note that these two need to be positioned at the very end of our rules, since we block every entrance and exit there. The reason i do this in this manner is because it will help you if you want to add further code afterwards to randomize entrances and exits. I am also assuming that every entrance is downwards and every exit is upwards. These are obviously all randomizable, but for this example i will keep things simple.
Exit the box
We are now at a point that we have a proper box. The player cannot leave the box but from the entrance or exit. Since we now know this, let’s add it in our Transitional Map.
We need to make a small adjustment now. This is quite crucial so stay with me. Remember that we always transfer the player back into the labyrinth? Now we need to add some conditions for that first. Our conditions are:
-Has the player exited the labyrinth through the exit?
-Has the player exited the labyrinth through the entrance?
The rest of the code will be cut and pasted so let’s begin:
If VroomCurrent=Ventrance, transfer player to (map of the entrance of the labyrinth) – The player has exited through the entrance
If VroomCurrent=Vexit, transfer player to (map of the exit of the labyrinth) – The player has exited through the exit
(the player hasn’t exited the labyrinth so in here we will cut and paste the rest of the code)
Transfer player to (Sample Room, VposX, VposY)
We’ve done it! Now we have a box with an entrance and an exit. Each room is connected and our machine knows exactly where the player is. This “super” map, built of 9 maps, built out of a single map, is our area where our labyrinth will be built.
Building the labyrinth – First steps
The first thing a labyrinth needs, in my humble opinion, is that its solution must never be a straight line from the entrance to the exit. In this example our entrance is room 2 and our exit is room 8. This means that room 5 must have at least one exit blocked, out of the ones leading to the exit or the entrance. In this example these exits are its top and bottom ones.
Since we want this to be random, let’s do so. Go to our “Creation” and add another variable:
Now we have a random variable that will indicate which one of these is permanently blocked. Let’s say that 1 means the bottom exit and 2 means the top one. Let’s add this to our rules. Go to “Rules” and add:
If VroomCurrent=5 AND VmiddleBlock=1, switch DOWN =true
If VroomCurrent=5 AND VmiddleBlock=2, switch UP =true
If you test it, you will see that once you are in room 5, in the middle of the box, you will have one of the two exits blocked. However, right now, we only have the blocks exiting room 5, but not the ones entering it. Let’s make this happen!
If VroomCurrent=2 AND VmiddleBlock=1, switch UP =true
If VroomCurrent=8 AND VmiddleBlock=2, switch DOWN =true
Now it starts gaining continuity. Now you are starting to feel like you are indeed inside a box, and it might even begin resembling something of a labyrinth. However, a labyrinth is supposed to have only one solution.
Did you ever solve labyrinths on paper? The “cheating” way was to solve them starting from the exit. So this is what we’re going to do in order to create our solution. We need to make sure that only one path is valid, starting from the exit.
Creating a solution – Top
So, starting at the exit, we are found in room 8. This room has three exits, RIGHT, DOWN and LEFT. So let’s add a random variable to randomize which one of these exits is part of the labyrinth’s solution. Let’s go to our “Creation” and add:
Let’s say that 1 means LEFT, 2 means RIGHT and 3 means DOWN.
Now we are at a pickle, since the correct solution might be DOWN but our VmiddleBlock might be 2, blocking our way. Let’s make sure this doesn’t happen by transforming our code:
If VtopSol<3, Break Loop
If VmiddleBlock!=2, Break Loop
Note three things here. First, “!=” means “not equal to”. Second, once a Loop hits the Break Loop command it will stop whatever it’s doing and continue reading whatever there is after the loop. Third, if it doesn’t encounter the Break Loop command, it will go back up and repeat the loop from the first command. This means that if VtopSol=3 and VmiddleBlock=2 the Loop will just repeat.
Ok, so now we have a single solution starting from the exit. Let’s go add it to our Rules.
If VroomCurrent=8 AND VtopSol=1, switches RIGHT,DOWN =true
If VroomCurrent=8 AND VtopSol=2, switches LEFT,DOWN =true
If VroomCurrent=8 AND VtopSol=3, switches LEFT,RIGHT =true
Now we also need to add these to our adjacent rooms. Continue adding them to our Rules.
If VroomCurrent=9 AND VtopSol=1, switch LEFT =true
If VroomCurrent=9 AND VtopSol=3, switch LEFT =true
If VroomCurrent=7 AND VtopSol=2, switch RIGHT =true
If VroomCurrent=7 AND VtopSol=3, switch RIGHT =true
If VroomCurrent=5 AND VtopSol=1, switch UP =true
If VroomCurrent=5 AND VtopSol=2, switch UP =true
Creating a solution – Middle
Now we must continue in a similar manner, going downwards towards the entrance. If you have your paper handy, you will see that we are now either in room 7, 9 or 5. However, if we are in room 5, the path downwards is definitely blocked. We need to keep this in mind in our next step.
So if we are in rooms 7 or 9, we can only go downwards. If we are in room 5, we are already in the middle of the labyrinth. So we are now either in room 4,5 or 6. Remember that we said that if we are in room 5, the path downwards is definitely blocked. This means that no matter which room we are in, we only have 2 directions to go, and only 1 of these is correct. So back to our “Creation”. Add:
This will work along with VtopSol’s value, so that we know which room we were in. Remember:
When VtopSol=1 it means that we are in room 4 now.
When VtopSol=2 it means that we are in room 6.
When VtopSol=3 it means that we are in room 5 with the bottom exit blocked from VmiddleBlock.
So let’s go to our Rules and add:
If VroomCurrent=4 AND VmiddleSol=1 AND VtopSol=1, switch DOWN =true
If VroomCurrent=4 AND VmiddleSol=2 AND VtopSol=1, switch RIGHT =true
If VroomCurrent=6 AND VmiddleSol=1 AND VtopSol=2, switch DOWN =true
If VroomCurrent=6 AND VmiddleSol=2 AND VtopSol=2, switch LEFT =true
If VroomCurrent=5 AND VmiddleSol=1 AND VtopSol=3, switch LEFT =true
If VroomCurrent=5 AND VmiddleSol=2 AND VtopSol=3, switch RIGHT =true
And let’s add the same rules for the adjacent rooms:
If VroomCurrent=1 AND VmiddleSol=1 AND VtopSol=1, switch UP =true
If VroomCurrent=5 AND VmiddleSol=2 AND VtopSol=1, switch LEFT =true
If VroomCurrent=3 AND VmiddleSol=1 AND VtopSol=2, switch UP =true
If VroomCurrent=5 AND VmiddleSol=2 AND VtopSol=2, switch RIGHT =true
If VroomCurrent=4 AND VmiddleSol=1 AND VtopSol=3, switch RIGHT =true
If VroomCurrent=6 AND VmiddleSol=2 AND VtopSol=3, switch LEFT =true
Creating a solution – Bot
Note that if VtopSol is 1 or 2 (we are in room 4 or 6), VmiddleSol is 1 (unable to go downwards) and VmiddleBlock is 2, then there are still 2 solutions, since room 5 is also connected to the entrance. So we need a condition to fix this.
Go back to our Creation and add:
Let’s say that this means that if the number is 1, then the correct solution is from the right or left from the entrance, while if it’s 2, the correct solution is from room 5 to the entrance. Since the path from room 5 might be already blocked though, we need to transform this code as well, just like we did with the other one.
If VbotSol=1, Break Loop
If VmiddleBlock!=1, Break Loop
And there we have it. If it’s 1, then it means that we will solve it from the sides of the entrance, while if it’s 2 we will check if the VmiddleBlock blocks the path from room 5 to the entrance. If it does, we will just randomize it again.
Now, with this, we could just block the sides of the entrance accordingly. But we want a labyrinth, not a linear path. So, instead, we will block the paths of the rooms leading to the correct room, so that the player can go to them, but their path will be blocked. Let’s start in this case.
So, we said that when VbotSol is 2, the correct solution is through room 5. Now, if we are at room 6, everything is pretty much already blocked APART from the connection between rooms 5 and 4. Similarly, if we are at room 4, everything is blocked apart from the connection between rooms 5 and 6. So let’s add these to our Rules:
If VroomCurrent=5 AND VtopSol=1 AND VmiddleSol=1 AND VbotSol=2, switch RIGHT =true
If VroomCurrent=5 AND VtopSol=2 AND VmiddleSol=1 AND VbotSol=2, switch LEFT =true
Let’s also add these to their adjacent rooms:
If VroomCurrent=6 AND VtopSol=1 AND VmiddleSol=1 AND VbotSol=2, switch LEFT =true
If VroomCurrent=4 AND VtopSol=2 AND VmiddleSol=1 AND VbotSol=2, switch RIGHT =true
Now the only thing that’s left (and i swear we’re done), is to add the rules for VbotSol=1. This means the correct solution is from a side to the entrance. This means we will also block room 5. Let’s do that:
If VroomCurrent=5 AND VbotSol=1, switch DOWN =true
and its adjacent room:
If VroomCurrent=2 AND VbotSol=1, switch UP =true
and now look at your paper. We’re done! With these rules every other possible solution has already been blocked, leaving only 1 valid solution to our labyrinth, while still retaining many possible paths to the exit. Now, although solving it from the exit is absolutely linear, solving it from the entrance is not. And that’s exactly what we wanted!
In this manner, you will always have a brand new labyrinth each time the player re-enters it.
Cleaning our code
Our code right now probably looks like Frankenstein’s monster. I could just post my code directly, but i wanted you to follow my logic, rather than just copy and paste it. Anyway, our code must be cleaned now but that’s the simplest part.
Go to your “Rules” and see which commands can be grouped together. For example, we don’t need 1000 “If VroomCurrent=5”, we can just have one. So yeah, group everything up so it looks neat and feel free to experiment.
So what can you do now? Well, experiment with maps! For my labyrinth i created a dozen different maps with weird exits, and, in my Creation, i assigned a random map to a random room number. This means that not only will the labyrinth’s solution be always different, but also the actual maps that the player traverses.
I might try and make a more advanced guide that lets you randomize every single thing (including size and shape) but i have no idea if and when i will have that finished.
A very simple version of this would be to only allow one path in Vexit and one path from Ventrance and have a condition to block a straight line and change it, if that’s the case.
Shape of the labyrinth:
When we are talking about the shape of the labyrinth, we are not talking about different numbering of the rooms. The rooms will always form a box and will always be numbered as in this example. The difference will be that the rules will add blocks to completely remove rooms from the possible solutions. This is so that we don’t have to change the code when the player goes left, right, up or down every time for every different shape.
There is surely a way to automate possible solutions. This was just an example. Hell, there should be a way to automate solutions for any labyrinth size. A simple logic would be to block 2 random paths in Vexit, block 2 random paths in Ventrance, and, if the size of the labyrinth is larger than this example, have a program randomly selecting a valid path from the exit to the entrance and blocking all exits that it didn’t go through. This would need a lot more rules and coding, and all possible combinations.
The way this example worked is that we kept the entrance and exit completely static. If you are a more advanced user you could surely randomize the entrance and exit, or even add more exits (leading outside the labyrinth but to a different map for example). This is why we added that VroomCurrent=Ventrance in our Creation.
However, this would definitely need my previous point, to automate the solutions. It’s certaintly not that hard, but it would need a lot of tinkering to make it work correctly every time.
Size of the labyrinth:
I would suggest not to change the size of the labyrinth, unless your entire game depends on it. A 3×3 box worked wonders for me. You can change the maps to be bigger or smaller, instead of changing the total number of rooms. In any case, if you really want to make it bigger, you just have to add more rules. The logic remains the same. Solve the labyrinth from the exit towards the entrance, and soon enough you will find your labyrinth ready.
Switches, buttons, chests:
You can randomize these things as well. Maybe the correct way is through room 9, but there is a gate there that needs a key, which you find in room 7. In my labyrinths i always have a bonus rule in my Rules, that is that if the correct way is room 9, then the button that opens it is in room 7, and vice versa. I also have possible rewards in rooms 1 and 3, if the correct solution is through room 5.
Bosses, minibosses, easter eggs:
You can pretty much go crazy with labyrinths. You can have some sort of contract to chase a criminal, instead of solving the labyrinth. Or you can have labyrinths that change their solutions each time you change rooms and hide an easter egg somewhere there. They’re awesome!
In case i made any typos, please do tell me. It’s very frustrating to make typos when you’re typing something as crucial as commands (even pseudo-commands as in this example), and it may end up not working just because i missed something. Still, the logic remains the same.
This is the ending of RPG Maker MV How to Add Randomized Labyrinths Automatically Generated guide. I hope it will help you. If there is wrong or you have suggestions, please let’s know and comment us. Have fun.