Hardware Reference
In-Depth Information
mc.setBlocks(x, y, z, x+SIZE, y+SIZE, z+SIZE,
block.COBBLESTONE.id)
mc.setBlocks(x+1, y+1, z+1, x+SIZE-2, y+SIZE-2,
z+SIZE-2, block.AIR.id)
mc.setBlocks(x+3, y+SIZE-3, z, midx-3, midy+3, z,
block.GLASS.id)
mc.setBlocks(midx+3, y+SIZE-3, z, x+SIZE-3, midy-3, z,
block.GLASS.id)
mc.setBlocks(x, y+SIZE, z, x+SIZE, y+SIZE, z+SIZE,
block.SLATE.id)
mc.setBlocks(x+1, y+1, z+1, x+SIZE-1, y+1, z+SIZE-1,
block.WOOL.id, 7)
pos = mc.player.getTilePos()
x = pos.x
y = pos.y
z = pos.z
house()
4. Notice how, in the last statement of your program, you have just put the name
house() . This line will run the code that is now stored in the computer's mem-
ory, which was set up by the def house(): statement.
5. Save your program, move to a new location and run your program. You should
see a house get built in front of you.
You might be thinking at this point, “so what? . You changed your program by
moving some program statements around and it just does exactly the same
thing! Sometimes, when you are writing computer programs, it is necessary
to improve the layout or structure of the program first, before you can do more
amazing things with it afterwards. That is just what you have done here. You have
restructured your program slightly, so that it is now easier to reuse your house-
building code many times.
CHALLENGE
The house() function will always build the house relative to the coordinates
stored in x , y and z. Add some extra statements at the end of your program
that change the x , y and z variables and then insert another house() , and see
what happens. How many houses do you think you could build like this?
Search WWH ::




Custom Search