Screen-Shot-2017-05-01-at-2.21.16-PM-554x368.png

How to build a Square

8-10 yrs old

Computer Science

Use the companion app MakeCode to create a square using blocks of your choice.

avatar Submitted By: Minecraft Education

May 2, 2017

Skills

  • Creativity
  • Critical Thinking

Supporting Files


Learning Objectives

  • Learn to use repeat loop to build a square.

Guiding Ideas

In Minecraft: Education Edition, the Agent is your own personal Robot! You can create programs to make him move, build or dig for you in the game.

In this lesson, we will create basic commands we can use for our Agent.

To do this, we will use a special event in Microsoft MakeCode called the “On Chat Command” which is a useful way to teach students about functions.

In computer science, a “function” is a way to group commands together. For example, the function of Waving might group the following commands together:

  • Raise hand
  • Move hand left
  • Move hand rightIn this case, we will be creating some On Chat Commands that will tell our Agent what to do. Students can type the name of their functions into the Minecraft game to execute that function.

Student Activities

  • From the Player Toolbox drawer, drag and drop the On Chat Command block onto the coding Workspace.

 

The first command we will create is to teleport our Agent to our Player. Rename this On Chat Command to “come”

 

From the Agent Toolbox drawer, drag and drop the Agent Teleport to Player block onto the coding Workspace.

 

Drag the Agent Teleport to Player block under the On Chat Command event

In your Minecraft game, press ‘t’ to open the chat screen. Type “come” and press Enter. Step back, you should see your Agent right next to you!

Now, let’s add some commands to make your Agent move around. From the Player Toolbox drawer, drag and drop 4 of the On Chat Command blocks onto the coding Workspace.

Rename the 4 On Chat Command blocks to: “forward”, “back”, “left”, and “right”

From the Agent Toolbox drawer, drag and drop 2 of the Agent Move blocks onto the coding Workspace

Drag 1 of the Agent Move blocks under the On Chat Command “Forward” block, and drag the other one under the On Chat Command “Back” block.

Under the On Chat Command “Forward” block, change the number of blocks the agent will move forward by to 5 in the Agent Move block.

Under the On Chat Command “Back” block, using the drop-down menu change the direction the agent will move to back in the Agent Move block.

Under the On Chat Command “Back” block, change the number of blocks the agent will move backwards by to 5 in the Agent Move block.

From the Agent Toolbox drawer, drag and drop 2 of the Agent Turn blocks onto the coding Workspace

Drag 1 of the Agent Turn blocks under the On Chat Command “Left” block, and drag the other one under the On Chat Command “Right” block.

 In your Minecraft game, press ‘t’ to open the chat screen. Type “forward” and press Enter. Your Agent should move forward 5 blocks. Try using your other Agent commands “back”, “left”, and “right” to move your agent around in Minecraft.

Now, let’s add a command to have our Agent build something for us! Our Agent has his/her own Inventory, so we’ll need to make sure we give him/her some blocks first. In your Minecraft game, right-click on your Agent. This should open his/her inventory. Move some blocks over from your inventory to your Agent’s inventory.

Let’s have our agent build a square for us. This exercise introduces repetition and loops. From the Player Toolbox drawer, drag and drop the On Chat Command block onto the coding Workspace.

From the Agent Toolbox drawer, drag and drop the Agent Place on Move block onto the coding Workspace. This block will put your Agent into “Builder Mode”, so that he/she will automatically place a block every time he/she moves.

Drag the Agent Place on Move block under the On Chat Command “Square” block

In the Agent Place on Move block, using the drop-down menu, select true

To build a square, we need the Agent to move forward and turn 4 times. From the Loops Toolbox drawer, drag and drop the Repeat block onto the coding Workspace

Drag the Repeat block under the Agent Place on Move block

From the Agent Toolbox drawer, drag and drop the Agent Move block and the Agent Turn block onto the coding Workspace.

Drag the Agent Move block and the Agent Turn block into the Repeat loop

In the Agent Move block, change the number of blocks to 5

In your Minecraft game, press ‘t’ to open the chat screen. Type “square” and press Enter. Do you notice that your agent can’t place the last block? That’s because he/she is running into the first block. So, let’s handle placing this last block in code.

From the Agent Toolbox drawer, drag and drop an Agent Move block onto the coding Workspace.

Drag the Agent Move block under the Repeat loop

Performance Expectations

  • Ask your students how would you add height to their existent structure?
  • Ask students to change the shape of the structure. What changes to the existing code would they have to make to create a rectangle for example?

Skills

  • Creativity
  • Critical Thinking

External References

Supporting Files