Introduction
15 minMinecraft has a robot in it that most players never meet. It is called the Agent, it does exactly what you tell it, and by the end of today you will type one word in the chat box and watch it walk.
Minecraft Education is Minecraft with a coding window built in. It adds two things ordinary Minecraft does not have, and the whole course rests on them.
- Code Builder — a coding window inside the game, opened with
C. You drag blocks together to build a program, so there is no typing and no spelling mistakes. - The Agent — a small robot that belongs to you. It cannot be hurt, it carries its own items, and it does exactly what your program says, including when your program is wrong.
How a program starts
Your program does not run on its own. It waits for you to type a word in the chat box. That is what the on chat command block does: you give the command a name, and typing that name in chat runs everything inside it.
So the Agent is the worker, the MakeCode program is the instructions, and the chat command is the start button.
The Agent has a front
The Agent has a face. Forward means whichever way its face is pointing — not north, and not the way you are looking.
That one idea causes more confusion than anything else in this course, so here it is as a rule:
agent movechanges where the Agent is. It never changes which way it faces.agent turnchanges which way it faces. It never changes where it is.
Stand up and try it yourself. Face the door and take three steps forward. Now turn right and take three more steps forward. You walked "forward" both times and you went two different ways — because in between you changed which way your front was pointing.
Six directions, not two
The agent move block has a dropdown, and it holds six directions:
| Direction | What the Agent does |
|---|---|
| forward | walks the way it is facing |
| back | walks backwards, still facing the same way |
| left | slides sideways to its left, still facing the same way |
| right | slides sideways to its right, still facing the same way |
| up | rises straight up into the air |
| down | drops straight down |
Left and right slide. They do not turn. The Agent finishes facing exactly the way it started.
Teleport is your reset button
agent teleport to player puts the Agent beside you instantly. Start almost every program with it. Then the program does the same thing every time you run it, instead of carrying on from wherever the Agent happened to stop last time.
What you will be able to do
- Create a flat Minecraft Education world that is set up for coding.
- Move, fly, place and break blocks with the keyboard and mouse.
- Open Code Builder, start a MakeCode project, and bring the Agent to you.
- Write
on chat commandprograms that move, turn and teleport the Agent.
Warm-up — the thousand-block wall
Placing one block takes about a second. A hundred blocks is roughly two minutes of clicking. A thousand is nearly seventeen minutes — and a real build is far bigger than that.
If a robot could place them for you, what would you have to tell it? Three things: where to start, what to place, and how many times. That is a program. Today we meet the robot; the "how many times" part is Lesson 3.
Basic
20 minFollow along on your own computer. Everyone should finish this part with the same working program.
Step 1 — Build a flat world
🔥 The world must be a flat world. On hilly ground the Agent walks into a slope and stops dead, and a shape walked across a hillside cannot be seen. Every lesson in this section assumes flat ground.
- Open Minecraft Education and click Play.
- Click Create New, then Create New World.
- Set World Type to Flat. This is the setting that matters most today.
- Set Game Mode to Creative and Difficulty to Peaceful.
- Scroll down and turn on Activate Cheats and Show Coordinates.
- Name the world
agent-school, then click Create.
Five settings decide whether coding works at all, so we set them every time:
| Setting | Value | Why |
|---|---|---|
| World Type | Flat | No hills. The Agent never walks into a slope, and you can see the whole shape it walks. |
| Game Mode | Creative | Unlimited blocks, and you can fly. Nothing to mine, so all the time goes on coding. |
| Difficulty | Peaceful | Nothing attacks you while your head is in the code window. |
| Activate Cheats | ON | Commands only work with this on. Section 2 needs it every lesson. |
| Show Coordinates | ON | Three numbers telling you where you are. You will need them in Challenge 2. |
Step 2 — Learn the controls
Spend three minutes flying about and placing a few blocks. These are the only controls this course needs:
WASD— walkSpacetwice — fly or landSpace— fly up,Shift— fly down
Challenge 1
15 minWalk a big M.
The Agent leaves no trail behind it, but you can watch it walk. Today you make it trace the letter M, six blocks tall and four blocks wide.
- Fly to a clear, flat piece of ground and land. Face whichever way you like.
- Press
Cand start a new chat command calledm. - Begin it with the block that brings the Agent to where you are standing.
- Now make the Agent walk the outline of a letter M, 6 blocks tall and 4 blocks wide, in this order:
- up the left leg,
- across two blocks,
- halfway back down into the middle of the letter,
- straight back up again,
- across two more blocks,
- and down the right leg.
- Here is the catch: you may use only the
agent movedropdown. There must be noagent turnblock anywhere in the program. - Go back to the world, press
T, typemand pressEnter. Watch the whole walk.
It works if: the Agent traces a letter M six blocks tall, never rotates once, and finishes four blocks to the right of where it started.
Fullscreen it while you build — you can pause and scrub with the player's own controls.
Challenge 2
20 minWrite MC in the world.
MC stands for Minecraft. You are going to make the Agent walk both letters — and start from an exact spot, so they come out in the same place every single time.
- Stand where you want the letters to appear. Write down the three coordinate numbers from the top left of your screen.
- Press
Cand start a new chat command calledmc. - Begin it by teleporting the Agent to those exact three numbers, not to the player.
- Walk the letter M, exactly as you did in Challenge 1.
- Now teleport the Agent a second time, to a spot 2 blocks further along than where the M finished. That gap is what keeps the two letters from touching.
- From there, walk a letter C, also 6 blocks tall and 4 blocks wide. A C is open on one side, so it is three strokes and not four: along the bottom, up the side, and along the top.
- Go back to the world, type
mc, and watch both letters appear.
It works if: typing mc walks an M and then a C, side by side with a 2-block gap between them, in exactly the same place every time — even when you run it standing somewhere completely different.
Fullscreen it while you build — you can pause and scrub with the player's own controls.
Challenge 3
25 minJump over the wall.
The Agent can move up and down, not only forward and back. Prove it.
- Fly to a clear, flat piece of ground and land.
- By hand, build a wall in front of you: 3 blocks high and 3 blocks wide, about 4 blocks in front of where you are standing. Any material will do.
- Write one new chat command called
overthat makes the Agent:- come to where you are standing,
- rise above the wall,
- travel across to the other side,
- come back down to the ground,
- and turn round so it is facing you.
You may only use blocks you have met today: the teleport block, agent move with its six directions, and agent turn.
It works if: you stand on your side of the wall, type over once, and the Agent finishes on the far side, on the ground, facing you — without breaking a single block on the way.
Fullscreen it while you build — you can pause and scrub with the player's own controls.
Extra challenge
spare timeThe complete square.
Write one chat command called square that makes the Agent:
- come to where you are standing,
- walk all the way around a square with sides of 5 blocks,
- and finish on the exact spot it started, facing the same direction it started.
It works if: you type square once and the Agent walks a full square and stops where it began, facing the way it faced at the start. If you had looked away, you should not be able to tell it had moved.
Hint — the repeat block
Count the blocks in your finished program. Every side is the same length, and every corner is the same turn, so you have dragged out the same two blocks over and over.
The Loops drawer has a block that does something a set number of times. Anything you drop inside it happens again and again:
That program bobs the Agent up and down three times. Change the 3 and it bobs a different number of times.
Your square has four identical corners. See whether you can build the same square with a repeat block instead, then count your blocks again. Write both numbers in your book — we come back to them in Lesson 3.
Fullscreen it while you build — you can pause and scrub with the player's own controls.