True Randomly Generating Mazes šŸŸ„ (Slim's Version)

:warning: Warning: This guide is advanced! :warning:

Introduction

Hello and welcome to quite possibly the hardest guide I will ever make. I will try my best to explain whatā€™s happening. The total memory is ~3-4% for a 3x3 maze. I got a lot of inspiration from Gimkitsuggestorā€™s research topic. By the end of this guide, you will have a great-looking random maze! Without further ado, letā€™s dig into it.

There are a total of the following items:

  • 14 Properties

  • 6 Triggers

  • 1 Wire Repeater

  • 6 Wires

  • 5 Counters

  • 1 Lifecycle

  • 20 Repeaters (This one is a joke)

  • Lots of barriers creating the maze.

If you do everything correctly, the final result should be similar to the photo above. [1]


List of All Properties

ā€¦and what they do.

  • currentSelectionX - This one is self-explanatory. It stores the x value of the current selection.

  • currentSelectionY - This one is also self-explanatory. It stores the y value of the current selection.

  • list - This property stores all the possible coordinate pairs. [2]

  • usedSections - We need to keep track of the sections we have already used. This property stores that information! It is in the same format as list.

  • backtrackTracking - This property is exclusive to the backtracking system for it to work properly. It isnā€™t required for the pathfinding of new sections, but is required for backtracking to work!

  • topAvailable - This property is a true/false value that tracks whether or not the randomizer can pick it. [3]

  • bottomAvailable - This property is a true/false value that tracks whether or not the randomizer can pick it.

  • leftAvailable - This property is a true/false value that tracks whether or not the randomizer can pick it.

  • rightAvailable - This property is a true/false value that tracks whether or not the randomizer can pick it.

  • topPicked - This property tracks if the randomizer has picked the top spot.

  • bottomPicked - This property tracks if the randomizer has picked the bottom spot.

  • leftPicked - This property tracks if the randomizer has picked the left spot.

  • rightPicked - This property tracks if the randomizer has picked the right spot.

  • numUsedSections - This tracks the number of spots the system has chosen. If it has used up every section, then the system stops.


All 6 of the Trigger's Code

Trigger #1

Iā€™m glad I didnā€™t spend too much time writing everything above this, otherwise I would have no yapping left to explain the system. For the first trigger, you must set up the following properties. The scope and channel settings should be set to default on all of the properties.

Property Name: currentSelectionX

Property Type: Number

Default Value: [YOUR DEFAULT X-VALUE GOES HERE] (My default value is 4)
Property Name: currentSelectionY

Property Type: Number

Default Value: [YOUR DEFAULT Y-VALUE GOES HERE] (My default value is 3)
Property Name: leftAvailable

Property Type: true/false

Default Value: FALSE
Property Name: rightAvailable

Property Type: true/false

Default Value: FALSE

Once you have all these properties set up, reference to the picture below for the following paragraph(s).

Note: A lifecycle listens for the game start. The lifecycle activates the first trigger on "start".

The first trigger accomplishes setting the x and y variables to currentSelectionX and currentSelectionY and finding the coordinates of the adjacent left and right cells. The trigger sets leftCheck and rightCheck to these coordinates. You might be wondering why I have a lot of math involved in those variables. Well, Iā€™m so glad you asked! [4] The way Iā€™m doing coordinates is basically combining the x and y with a ā€œcreate text withā€ block. Now you might wonder why Iā€™m not doing that. Variables can only be set to a numerical value, so the ā€œcreate text with blockā€ doesnā€™t apply to the variableā€™s logic. [5] If x was 2, and y was 3, then the coordinates would look like 23 instead of (2, 3) in the code. This is more efficient and saves crucial blocks.


If you want to learn more how the variables work, click here. If not, don't worry about it and continue on with the tutorial.

The math portion might confuse many people, but if you understand math well, you will probably know what I mean. Letā€™s pretend we have the numbers 2 and 3. They want to come together to form 23, but can only do this by doing math equations. The 3 can easily get to the oneā€™s spot by adding, but what about the 2? The answer is much simpler than you might think! By doing multiplication, we can times the digit by ten. The 2 is now in the tenā€™s spot; all thatā€™s left is adding them together! Now you are a certified math nerd and Iā€™m an accredited yapper. :sunglasses:


The part that might seem the most advanced is the ā€œfind first occurrence ofā€ blocks. We have the (possible) coordinates of the right and left cells, now we need to check if they exist, and if they are used. We can do this using the ā€œfind first occurrence ofā€ block. While this block is within an if, it will produce an output of 0 if it is not found within the selected text. We can use this to our advantage and check if itā€™s in our list of possible coordinates by using not equal to 0. Checking if itā€™s not equal to 0 will produce a true output if it is in the list of possible coordinates. Now we need to find out if the coordinate has been used. [6] We can check if it is not in the property by doing if = to 0.

If both these checks pass, it is a valid spot for the randomizer.


Trigger #2

Properties you will need to set up. Properties not in here should already be set up.

Property Name: topAvailable

Property Type: true/false

Default Value: FALSE
Property Name: bottomAvailable

Property Type: true/false

Default Value: FALSE

That was a lot, right? Well, I have good news for you. This second trigger has almost all the same blocks, but the variables, properties, and broadcast messages differ slightly. Copy this code to your second trigger. Iā€™m so glad I donā€™t have to explain the second trigger. If you donā€™t understand it, read the description for the first trigger.

One thing to note: The second trigger receives on the channel "continueChecks", broadcasted from the first trigger's code. The second trigger broadcasts on "startRandomizer" to the third trigger.

___

Trigger #3

Properties you will need to create.

Property Name: topPicked

Property Type: Number

Default Value: 0
Property Name: bottomPicked

Property Type: Number

Default Value: 0
Property Name: rightPicked

Property Type: Number

Default Value: 0
Property Name: leftPicked

Property Type: Number

Default Value: 0

Oh boy, here we go with the third trigger. This trigger receives on startRandomizer, and copy the following code to your third trigger. Read the paragraphs below the image for a description.

First things first, whatā€™s a randomizer without a random integer block? We set b to a random integer from 1 to 4. Next, we need to check if all the cells are unavailable. If they are, then it starts to backtrack. I included an activity feed message for testing. In the else section, create an if statement checking to see if b is 1, 2, etc. Create if statements inside each to check if the cells are available. Please let me know if you find a more effective way to create this randomizer. I canā€™t think of more things to explain- all this trigger does is randomly pick one. :sweat_smile:


Counters

There are four counters you need to set up- along with a property for each. Set up each of the triggers as follows. All other settings will be default.

Counter 1

Starting Value: 0

Increment Counter when receiving on: topPicked

Update Property: Yes

Property To Update: topPicked

Target Value: 1

Counter 2

Starting Value: 0

Increment Counter when receiving on: bottomPicked

Update Property: Yes

Property To Update: bottomPicked

Target Value: 1

Counter 3

Starting Value: 0

Increment Counter when receiving on: leftPicked

Update Property: Yes

Property To Update: leftPicked

Target Value: 1

Counter 4

Starting Value: 0

Increment Counter when receiving on: rightPicked

Update Property: Yes

Property To Update: rightPicked

Target Value: 1

Wire all the counters so that when the target value is reached, it goes to a wire repeater with a delay of 0.1 seconds. Wire the wire repeater to the 4th trigger.


Trigger #4 & #5

This might initially seem a little complicated, but getting under the block limit is necessary. I will organize the steps the code takes in bullet points this time around.

  • First, the 4th trigger imports x and y.

  • Next, the trigger checks to see which spot was chosen. It sets the x and y properties to the updated coordinates.

IMPORTANT: The x and y Variables are set to the old coordinates. The Properties are set to the new ones.

  • Then, trigger four sets the variable newCoords and oldCoords to the old set of coordinates and the new set of coordinates.

  • Finally, it broadcasts on a combination of the old and new coordinates to disable certain maze walls, reset properties, add the new set of coordinates to usedSections, and broadcast on channel prepBacktracking.

For the 5th trigger, just copy the code from the image. I will explain the last and final trigger with an explanation of the property setup. Donā€™t forget to have the 5th trigger trigger when receiving on prepBacktrack!


Trigger #6

The last and final trigger. Set up this last property, then connect this counter to the property.

Property

Property Name: numUsedSections

Property Type: Number

Default Value: 0


Counter

Starting Value: 1

Increment Counter when receiving on: resetCounters

Update Property: Yes

Property To Update: numUsedSections

Target Value: None

We increment the counter on resetCounters because we need this to increase exactly once after every run. Instead of using two more blocks, we reuse the channel. **Do not confuse this with ā€œreset counter when receiving onā€. Put it in ā€œIncrement counter when receiving onā€.

Copy this code into the last trigger. (The 6th one.)

Some unpacking:

  • We set a variable, backTracking, to the property, backTracking.

  • The next four if statements convert text to numbers.

  • We set the property, backTracking, to the variable, backTracking.

  • We set the x and y variables appropriately.

  • The last if statement stops the system if all the cells have been used.

The property, backTracking, looks like this: 3432343243223. Each two numbers is a pair of coordinates. If the property was 3233, it would house the coordinates 32 (3, 2), and 33 (3, 3). Each time it back tracks, it removes the last two numbers from its line, setting the previous coordinates as the current x and y values.


Building the Maze

The image above shows the grid system in this 3x3 maze. It checks the surrounding cells, so the lowest it could go in this scenario is (1, 1). If the lowest was 0, it would break the whole thing because anything times 0 is 0. Move to the next image. >:D

Set up a grid like this. The black barriers arenā€™t necessary, but the white ones are. The black barriers show each cell and has a giving coordinate. It is very easy to set up the black ones, all you need to do is set the ā€œdeactivate barrier when receiving onā€ to the coordinate it is given.

Set the white barrier to deactivate when receiving on a combination of both of the surrounding barrierā€™s channels. It doesnā€™t matter which order it goes in; the system broadcasts both.

Here is an image of one of my black barriers.

Here is an image of one of my white barriers.


Exit

The end result is this.
Untitled video - Made with Clipchamp (2)

Let me know if you have any questions, concerns, or feedback. If you enjoyed or liked the guide, I kindly ask you to give the guide a :heart:. I have some exit polls down below; please put some thought into it.

Do you like bulleted instructions like in triggers #4 & #5, or do you prefer the other style with paragraphs? I wonā€™t judge. (probably)
  • Bulleted List
  • Paragraphs
0 voters
Overall rating on a scale of 1-5?
  • 1
  • 2
  • 3
  • 4
  • 5
0 voters
Difficulty?
  • 1/10
  • 2/10
  • 3/10
  • 4/10
  • 5/10
  • 6/10
  • 7/10
  • 8/10
  • 9/10
  • 10/10
0 voters
More pictures?
  • No need, the amount here already is fine.
  • Eh
  • Yes, please, I need more. (Reply with what photo(s) are needed.)
0 voters
Should I make a part 2 that has completely random gameplay? (Ex. Random Characters, Quests, Rewards, Endings, etc.) [7]
  • Yes
  • No
0 voters
Are you tired of these polls? Or should I say two tired? :wheel: :wheel:
  • Yes
  • No
  • ._. you really just made that joke
0 voters

Thanks,

Slim


  1. I caught my gim blinking! :D ā†©ļøŽ

  2. Examples include 22 (2, 2), 23 (2, 3), 24 (2, 4) ā†©ļøŽ

  3. The Floor vibes settling in. ā†©ļøŽ

  4. /j ā†©ļøŽ

  5. A property can be set to a string, boolean, or intager. ā†©ļøŽ

  6. By default, only the starting cell should be in there. ā†©ļøŽ

  7. If the poll says yes I probably wonā€™t make it for quite a while. ā†©ļøŽ

27 Likes

image

I had my hopes too high. I demand an explanation.

I was gonna say that instead of ā€œlets dig into itā€


Feel free to ask me questions.

5 Likes

Such a genuine guide with actual effort

But theres no forumers these days with half a brain to understand it at all

ā€˜Twas a shame.

Really good though! I made a similar system for a game I ended up raging on (for this EXACT reason, and now I regret deleting it :skull:). Now that I look over it, I believed I probably messed up the properties (which seems to happen a lot lol).

:clap:t4::clap:t4:

6 Likes

Thank you. I spent a lot of time and effort on it.

I honestly think we could get rid of the 5th trigger and squeeze it into the 4th but I donā€™t have the brainpower to do that.

6 Likes

Excellent guide, Slim. Been waiting for this for a while and it definitely seems solid.
The only thing Iā€™d say is maybe format each part into a drop-down chain? Makes it a little easier to follow, in my opinion.

9 Likes

Iā€™ve been waiting for this.

And itā€™s as good as I could have imagined!
This is really complex, something we need more of on the forums.


One suggestion:
In pictures like these-


You have a lot of "in text "backtrackTracking" get letter # from end... with the same number. Iā€™ve found for some reason that these can be saved in a variable (at least it worked for my system), so yeah even more block condensation.


Iā€™ll ask about this one for you.


Again, stellar guide! Looks like I need to get back to working on my system (which might have to use 2 properties :sob:).


Update: fixed broken image

6 Likes

new slim guide just dropped :speaking_head: :fire: :fire:
as I expected the block code is deadly :skull:
I bet I could implement this into my racing game in a wayā€¦

randomly generated tracks??? :smiling_imp:

8 Likes

Yeah I noticed that. Forgot to put that in the guide. Iā€™m going to edit this tomorrow based off of feedback, promise.

6 Likes

My thought process when I saw this: Finally. Finally. Finally. Finally. And I devoured it so hard. THIS IS AWESOME! Thanks for finally posting! One question: Does this same system work for a 4x4 or a 5x5 grid?

5 Likes

Oh uhh yes it should. You would need to edit some properties and expand the 6th trigger, but yeah itā€™s basically the same code but tweaked a little if you do a different grid.

3 Likes

Ha thanks! Does it affect that much memory, though?

It shouldnā€™t. The only thing that would expand the memory is adding onto the 6th trigger. You need to manually check if itā€™s equal to each number thatā€™s possible. If you have too many it could lead to a 7th trigger.

The memory will change based off the about of barriers too but it should never get above 7% I think.

5 Likes

Rip my notifications itā€™s getting blown up by likes.

Apparently @Gimpenetrable voted in one of the polls :D

5 Likes

I donā€™t think I could take more than 7 triggers, my brain canā€™t function with that much stuff around me

2 Likes

is there smth wring with that

3 Likes

Nope!

2 Likes

This is amazing! The length of the guide! Iā€™m so happy that a guide for this was made, and Iā€™m happy you got it published.

5 Likes

Great guide Slim! Iā€™ve been following the research topic since it started, and itā€™s really cool to see this finally come true!

5 Likes

ā€œDiveā€ was removed from the block list, I donā€™t know why it was on there, but it was probably from an exported list.

12 Likes

This guide is great
(My brain is freaking out over the amount of block code)

5 Likes