Application in CodeCraft
A list of all red materials
In this example we use a list to store all materials that are red, then build a column with those materials.
# Red blocks
red_blocks = ['box_red', 'linen_red', 'redstone'];
def block_m(x, y, z, m):
game.set_block(Position(x, y, z), materials[m])
for i in range(len(red_blocks)):
block_m(0, i + 1, -10, red_blocks[i])
List of lists
An element in a list can itself be a list. In this example, we created a list called blocks
that stores lists containing the coordinates and materials of various blocks in this format: [x, y, z, m]
blocks = [[2, 4, -9, 56], [2, 2, -9, 56], [3, 3, -10, 59], [4, 2, -9, 56], [4, 4, -9, 56]]
for b in blocks:
block_m(b[0], b[1], b[2], b[3])
See the picture below. We built 4 red blocks and a yellow block in the middle. Their location and material values [x, y, z, m]
are stored in blocks
as five number lists. Variable b
in the for
loop represents each list within blocks
.