Want to compress your code? If you don’t know how this guide will teach you!
There is a intro to blocks guide too! Go check it out!
The Beginning
The first thing to mention is that code blocks take up 500 memory! So try to avoid them if it is a simple if statement you need to run. You can use checkers to run if statements so it saves memory! [1]
You only have 75 blocks per 500 memory, so compressing your code is crucial!
If you want to edit, please read post #8
Using Variables
Using Variables saves valuable blocks that you need. If you need to run the code below a lot, use a variable to store that property instead! It requires 3 blocks at first, but then you only need to use 1 block every time you need it.
Get Property >>> Players
For example, this code could use work. I got the property “Players” a lot.
This is the compressed version.
The Gear Button
This button up here- is one of the most crucial ways to compress blocks.
It helps combine multiple blocks, saving space, and giving room for more blocks
Here is an example:
Let’s say we are making a long section of block code and they are all if statements.
WOAH! That’s a whole lotta blocks, But, we can save block space by using the gear button!
We just change it to else if statements, and move the channels and properties, and we’d save lots of space!
2 blocks saved! You could even go a step further by changing the last section to else. This Button would be even more useful if you place blocks, upon blocks, upon blocks…
You can do the same with text blocks!
Counters
Did you know using a huge 500-memory code block to set a true/false property isn’t worth it? There is a MUCH better way to save memory on this!
Use the counter to set a number property instead! 0 is going to represent false, and 1 is going to represent true.
Now if you ever want to change a number property that is acting like a true/false property, use channels or wires to increment or decrement the counter!
Advanced Compressing [2]
Let’s start this harder section with a recent problem I had. I was making a battle-royal game, and I needed to teleport players each in a different spot. [3] I won’t go into detail about the post, but the solution was to create a randomizer and based on what it was, it teleported you to a different spot. I could have done a bunch of if statements, but that is too chunky of code. Instead, I broadcasted on a channel of the number, and each teleporter received on a number. The code is screenshotted below.
[4]
I did the same thing to my coordinate system, I broadcasted the position, and if anything was received right there, it would activate. A screenshot is below.
That’s it! Hope you learned a thing or two!
Thank you to these user(s) for helping create this guide.
- @Bardy_2913 - Gear Section
Polls
Checkers only use 35 memory. ↩︎
Sorta ↩︎
My problem was I had no idea how to do this, but I realized this was a great example of not using a million if statements. ↩︎
A little tip is when you are doing this, in order to broadcast off of a variable, you have to turn it into text with the “Create Text With” block. ↩︎