Hardware Reference
In-Depth Information
5. Your tower is going to be 50 blocks high, so start building it with a for loop that
counts 50 times. Don't forget the colon ( : ) at the end of the line:
for a in range(50):
6. The next line is indented, because it belongs to the body of the for loop. The y
coordinate controls height within the Minecraft world, so add the loop control
variable a onto the player's y position. This tells the program to build at an
increasing height in the Minecraft world each time round the loop:
mc.setBlock(pos.x+3, pos.y+a, pos.z, block.STONE.id)
7. Save the program and run it. Has it worked? Your for loop should have created
a massive tower in front of your player, similar to the one in Figure  3-3. Start
counting—is it 50 blocks high?
FIGURE.3-3 This huge tower was created inside the Minecraft world using a
for  loop.
In the previous code, the for loop cycles around 50 times, and each time round
the loop, it runs the indented lines below it, such that the a variable has a value
one bigger than the previous time round the loop. It adds the value in the a
variable (the loop control variable) onto the pos.y variable (which is the players
height above bedrock). This then creates a tower 50 blocks high!
Search WWH ::




Custom Search