In our first class we learned about functions. A function is a task to do something. Some of the functions we used are mc.postToChat to post a message to Minecraft and time.sleep to pause our program execution for 1 second. In today's adventure, we learn more about functions. We will use new functions to build circles and spheres in Minecraft.
In our previous class we were introduced to functions. Sometimes you need more than just a task name to complete a task.
E.g., "Practice you writing!", is not enough, you want to know for how long. "Practice your writing for 15 minutes!" is more helpful.
If we had a function for the "practice writing" task, we would write is as,
practiceWriting(15)
the additional pieces information we pass to a function are called its arguments. A function can have zero or more arguments just like a real tasks need zero or more pieces of information to complete them. Both the functions that you used so far needed arguments. For the function examples below,
mc.postToChat("Hi Kids")
time.sleep(1)
The mc.postToChat function needs the argument "Hi Kids" which is the message to post to the Minecraft chat window. The time.sleep function needs the argument 1 which is the number of seconds to pause the program from running.
The first building function drawings.drawMyCircle uses two arguments - the radius of the circle to build and the block id to use for building the circle.
drawings.drawMyCircle(radius,blockId)
# e.g., drawings.drawMyCircle(5,block.STONE.id)
The second building function drawings.drawMySphere uses two arguments - the radius of the sphere to build and the block id to use for building the sphere.
drawings.drawMySphere(radius,blockId)
# e.g., drawings.drawMySphere(5,block.STONE.id)
In the following tasks, you will use these functions with different arguments to build circles and spheres in Minecraft.
Note: Before you start your tasks, start Minecraft and run the program cell below to make the building functions available to your programs.
In [ ]:
import sys
sys.path.append('/home/pi/minecraft-programming')
import mcpi.block as block
import time
import drawings
In [ ]:
# Task 1 program
In [ ]:
# Task 2 program
In [ ]:
# Task 3 program
In [ ]:
# Task 4 program