Now let’s go ahead and finish the rest of the code, type in the code as shown to complete the program.
Here we first have another infinte loop that allows us to constantly get the player’s position.
However, inside this loop we now have ANOTHER loop, the for loop.
Here, we have the for loop repeat 19 times, which will get our lava to shoot 19 blocks forward. (Why isn’t it 20?)
We do this by placing a lava block, waiting for a small delay, and the replacing it with an air block. Making it look like it is shooting out (when in reality it’s just moving a block at a time!)
The reason it goes forward 19 blocks is because we use the variable “i”. Remember, because “i” is the variable we use for our for loop, as the loop goes on, i changes. In the end, by using “i”, we get the block to go forward one block at a time!
Now that we’re done, let’s test it out!
If done correctly, we should see lava shoot out wherever we walk! If not, go back and double check all your code for any errors.
Think of some ways you might be able to modify this program to change it or even make it better!