8-10 yrs old
Computer Science
May 2, 2017
In computer science, a “function” is a way to group commands together. For example, the function of Waving might group the following commands together:
From the Player Toolbox drawer, drag and drop the On Chat Command block onto the
coding Workspace.
Rename this command to “rain”
From the GamePlay Toolbox drawer, drag and drop the Weather block onto the coding Workspace.
Drag the Weather block under the On Chat Command event
Using the drop-down menu, change the weather to rain
In your Minecraft game, press ‘t’ to open the chat screen. Type “rain” and press Enter. You should see it start raining in Minecraft!
From the Mobs Toolbox drawer, drag and drop the Spawn Animal at Position block onto the coding Workspace.
Drag the Spawn Animal at Position block under the On Chat Command event
Use the Animal block drop-down menu to select an ocelot
Right-click on the Spawn Animal at Position block to open the context menu, and select Duplicate to copy the block
Drag the second Spawn Animal at Position block underneath the first
Use the Animal block drop-down menu on the second Spawn Animal at Position block to select a wolf
Our Rain function will now spawn 1 ocelot and 1 wolf at the Player’s position before making it rain. Let’s use a parameter and a loop to spawn multiple animals. From the Loops Toolbox drawer, drag and drop the Repeat block onto the coding Workspace.
Position the Repeat loop under the On Chat Command block, and drag the 2 Spawn Animal at Position blocks inside the Repeat loop
Click on the blue cog/gearwheel icon in the On Chat Command block, drag and drop a number parameter block under the Command Arguments block. This will create a number parameter for our Rain function. Click on the blue cog/gearwheel icon again to close the Parameters menu.
From the Variables Toolbox drawer, drag and drop the number block onto the coding Workspace.
Drag the number block into the Repeat loop block
Let’s change the position where our Ocelots and Wolves are spawning. Right now, they are spawning at the Player’s position at ~0 ~0 ~0. From the Positions Toolbox drawer, drag and drop a Pick Random Position block onto the coding Workspace.
We want our animals to spawn 5 blocks above our Player, and at random locations 10 blocks all around our Player. Set the values of your Pick Random Position block according to the following:
Right-click on the Pick Random Position block to open the context menu, and select Duplicate to copy the block
Drag and drop the 2 Pick Random Position blocks into the Spawn Animal at Position blocks. Your completed program should look like this:
In your Minecraft game, press ‘t’ to open the chat screen. Type: “rain 4”. You should see it start raining 4 ocelots and wolves all around you in Minecraft! Now try typing different numbers into your Rain function: “rain 40”, or “rain 400”.
Sign up for the Minecraft: Education Edition newsletter. We promise to respect your inbox.