• Hey! Register here to create your account, engage with the community, and talk about what is new!

Insert pre-existing code into new if blocks

StoryTellr

New member
Joined
Aug 13, 2024
Messages
6
Reaction score
0
Is there a way to insert pre-existing code into new if blocks?
 

CoderElias

Notorious member
Overlord
Joined
Jun 15, 2022
Messages
99
Reaction score
16
You can create a template without breaking the code line by sneaking and pressing your right mouse button while looking at a player event, function, or process. You can also sneak and break the code block to create a template, which will break the entire code line. This template is essentially a copy of the code line, and by placing it, you will effectively "paste" the code. This is how you can "copy & paste" code lines. If you want to place it inside the brackets of a new if block, you can do so by placing the template between the brackets. However, this might break the closing bracket, which could also break the code. If you're familiar with this issue, it’s quite easy to fix, but if you're not, it might be a bit confusing at first.




Let’s create this scenario: You create a code template consisting of two code blocks. You want to place this template inside a loop using the given template. You successfully put the code template between the loop’s brackets, but when you run the code, it only executes once, not continuously as it’s supposed to. This is likely because the ending bracket of the loop has been broken.



Now for the solution! Since the loop is missing a closing bracket, you need to add one yourself. First, type /p glitch to get a glitch stick. This stick can break individual blocks without breaking the entire code block. Now, at the end of the if block (where the closing bracket should be), place another code block. This block should match the starting bracket. So if the code was placed in a loop, place another loop at the end. Now break every block in that if block you just placed except the closing bracket (using the glitch stick). You should now have only the closing bracket left.



Sorry if this isn't what you meant, you can always ask me more questions.
 
Top Bottom