0835980980191991-Coding With Minecraft - Unit 4 - Variables
0835980980191991-Coding With Minecraft - Unit 4 - Variables
Unit 4 – 4 Lessons
60 minutes per lesson
Single Student
EDUCATION.MINECRAFT.NET
1
THEME OVERVIEW
In this unit, students will learn about the coding concept—variables. Variables are
important ways to store information and make programs more flexible and
adaptable. The unit will also build upon what was learned about events—students
will learn how to use a variable to pass additional information when an event
occurs. Students will participate in an unplugged activity, coding activities, and an
independent project.
LESSON OVERVIEW
All of the following lessons are approximately 45-60 minutes, depending on how
much time students are given to explore the coding activities:
• Lesson A: Introduction to Variables
• Lesson B: Coding with Variables
• Lesson C: Combining Variables
• Lesson D: Get Creative with Variables
LESSON OBJECTIVES
• Learn and apply the coding concept of variables
• Describe the different kinds of coding variables
• Explain the importance of variables in coding and while playing Minecraft
• Design an original project to apply the use of variables to create an
automated solution
MINECRAFT MECHANICS
C C
Summons the Agent and opens the MakeCode
interface
T T
Opens chat panel in Minecraft for commands to
be typed
2
ESC ESC
When a student wants to leave the game, leave
chat, or pause the game
CODING BLOCKS
On chat command
Runs the code when the student types the
chosen text in the chat window
On player (traveled)—walk/swim/fly/fall,
etc.
Runs code when the current player travels
a certain way
Print
Creates some text in the game world
Variable (set)
Assign (set) a variable’s value
Variable (change)
Change a variable’s value
Join
Add one text string to another to make one
big string
KEY VOCABULARY
Variable – a place in which computer stores things; each variable holds a specific
type of information
Number Variable – the coordinate represents a distance along the horizontal plane
east or west of the origin, just like real-world longitude values
String Variable – the coordinate represents a distance along the vertical plane up
or down from the origin, just like real-world altitude values
3
Boolean Variable – the coordinate represents a distance north or south of the
origin, just like real-world latitude values
Position Variable – a position that is based on the where the player is located (i.e.,
the distance from the player to an object or entity)
LESSON ACTIVITIES
Lesson A: Introduction to Variables (Slides 1-32)
Direct Instruction (Teacher-Led; “I Do”)
Welcome to back to Coding with Minecraft, a place to learn all about the basic
concepts of computer science. Over the next couple of sessions, we are going to
learn about variables. (slide 1)
Today, we are going to learn about what are variables and how we use them not
only in real-life, but how they are used in Minecraft. (slide 2)
Here are some examples of things computers might store as variables. (slide 5)
Each variable holds a specific type of information. The first time you use a variable,
you must set its type. From that point on, you can only store information of that
type in that variable.
4
password, the day three-dimensional
of the week space.
Variable names can be used in the place of values. Given the variables above, you
could make the following statements: (slide 8)
Cats + Dogs = 7
Say Greeting
Teleport to HousePosition
5
Assign values to each of the movement variables and the players should work
together to try to show those values to the rest of the class. Each of these
movements takes a number that tells the player how times to slap, clap, or snap.
Directions
In each round, two students will become the “computer”.
One student will “fetch” the stored information from memory while the other
students outputs the stored numbers for everyone to see.
• Demonstrate the three different movement in order: slap, clap, and snap.
Write the order on the whiteboard.
• Split the class up into teams.
• One student from each team will sit with an index card turned upside down
near them. They will need to reach for this so make it convenient. Or you
could have a 3rd teammate show the card.
• The index card will have 3 numbers on it. The first number is the number of
slaps, the second is the second of claps, and the third is the number of
snaps.
• Another student will be at the whiteboard ready to write.
• When the teacher says, “Go!”, the three variables are shown. The student in
the chair performs the actions and the person at the white board write
downs the numbers as they watch the teammate in the chair perform them.
The student at the whiteboard should not be able to see the index card.
• This is a relay race—the first team to finish correctly wins.
• Play several rounds or to a set victory number.
To keep game play balanced, teams should have the same total number of actions.
This will require preplanning, but will ensure fair game play.
For example, assume you have three teams. Their first cards with the three
variables might look like this:
Team 1 Slaps = 2
Claps = 1
Snaps = 4
Team 2 Slaps = 1
Claps = 4
Snaps = 2
Team 3 Slaps = 4
Claps = 1
Snaps = 2
6
The number of slaps, claps, and snaps for each team is different, but they are all
performing a total of seven actions to keep the game fair. The actions are varied to
also avoid teams looking at others to find the answer.
Variations:
• Change the order of actions from slap, clap, and snap TO clap, snap, and
slap.
• Let students suggest different movements to add to the slap, clap, and snap
sequence. They can then add another vehicle.
Have all students log into Minecraft: Education Edition. After students have logged
into the platform, navigate to the Coding with Minecraft subject kit. (slide 12) Once
in the Coding with Minecraft subject kit, select Unit 4: Coordinates to begin the
lesson. (slide 13)
• Step 6: From VARIABLES, replace the number 4 in repeat with num1 . (slide
20)
7
Run and test the program for Chicken Storm. Press “t” to open the chat window.
Enter “chickens” into the chat window. It’s raining hens! Now, if you enter
chickens 15 in the chat window, the variable num1 will take the value 15. (slide 21)
Coding Solution:
Challenges
• Challenge 1: Rename Num1 to Something More Meaningful
Let’s change the code so that you are not using Num1. The name num1
does not represent anything meaningful and could be hard to understand in
a big block of code. Instead, your new variable will be called ChickenNum
because it will represent the number you store—the number of chickens.
• Challenge 2: Give Feedback
Let’s have your chicken rain machine speak back to you! This will be kind of
like ordering at a drive-through window. Right before chickens start falling,
have your code say, “ChickenNum chickens! Coming right up!”
If you entered chickens 5 in the chat window, the response would be, “5
chickens! Coming right up!”
Then the five chickens would fall from the sky on your head.
To complete this challenge, you will need to consider:
o Figure out how to “say” things in the chat window.
o Use the join block to put together ChickenNum + “chickens! Coming
right up!”
o Put this new block in the right location in your code. If you put it in the
wrong spot, the chat window will respond many times.
8
Extensions
There are no rules for these extensions. See what you can come up with!
• Extension 1: Default Chicken Value
Now that you have programmed a chicken command that takes a number
variable and produces many chickens, it is good programming practice to
make sure to handle cases where the chickens command in the chat window
isn’t given a number. By default, ChickenNum has a value of 0. If you type
the chickens command, but forget to type a number after it, you will get a
couple of chickens, but not ten chickens.
o How could you change this code?
o What if raw chickens fell from the sky instead?
o Could you make a pattern of chickens fall: normal chicken, raw
chicken, normal chicken, raw chicken, and so on?
• Extension 2: Chicken Storm
We know that rain in a storm does not fall in a single, straight line. You could
improve the realism of the storm effect by using the pick random position
block from the positions toolbox drawer. This block will scatter the chickens
randomly around the area, as described by the two coordinates. You can
also vary the height of the drop so the chickens will land at different times.
You could even try this out with other animals or objects!
LESSON CONCLUSION
Upon completion of this lesson, students should be able to answer the following
questions: (slide 22)
9
2. What is one thing you were excited to learn about today?
Answer: Answers will vary
Conclude the lesson by reviewing the concepts covered in Lesson A. (slide 23)
Make sure you are set-up to demonstrate and lead the students through this
coding experience. It is best if you complete this activity on a device connected to a
projector or presentation screen. Split the screen and display the classroom
presentation alongside of the Minecraft world.
Have all students log into Minecraft: Education Edition. Students should continue
working in the same world from Lesson A. Directions for navigating to the previous
world can be found on slide 29.
You can use variables to count the number of times something happens in your
Minecraft world. You can use them to keep score or you can count things. In this
coding activity, we are going to use a conditional statement to cause something to
happen when our arrow counter gets to a certain number. (slide 30)
10
• Step 3: Drag a change variable inside the on arrow shot block. (slide 33)
• Step 4: Drag a say block underneath the change arrows block. (slide 34)
• Step 5: Put text together; Click on the Advanced category in the toolbox to
display the TEXT toolbox drawer. Drag the join block into say to replace the
“:)” string. (slide 35)
• Step 6: Join the variable message. In the first slot of join, enter “Arrows
Shot”. (slide 36)
• Step 7:
Coding Solution:
Then, you will need to publish and import the program into Code Builder.
Step 3: Select the green “Copy link” Step 4: Inside Code Builder, select the
button. “Import” button.
11
NOTE: If you are having difficulty with the copy link,
try using the short cut: press Ctrl + C (or Command +
C) on your device.
Step 5: Select the “Import URL” button. Step 6: Paste the Project URL. Then,
select the “Go ahead!” button.
Now, we are going to return to our Minecraft world to try out our code. However,
before we test the program, we need to give our player a bow and some arrows.
Use the search feature to find the materials quickly and place them into your
hotbar. (slide 38)
Try out your program. To shoot an arrow, hold down the right mouse button on
the keyboard (or simply press, hold until you see the +, and then release for
touch). If your code is running properly, you should see your arrow counter in the
top left-hand corner of the screen. As you continue to shoot arrows, your counter
should increase. (slide 39)
If time permits:
Challenge 1 – Modify the Message and Track 10 Arrows
12
The player only gets 10 shots from now on. You want the message to display the
number of shots the player has left out of the 10 arrows. Can you modify the
message and variable to do this?
Change the text message so it is appropriate for the new situation.
• Set arrows equal to 10 when your code starts.
• Change arrows so it subtracts when arrows are shot.
Challenge 2 – Provide a Message When a Player Runs Out of Arrows
Set up this conditional statement somewhere in your code to display a message or
make something happen when your player runs out of arrows.
Extensions
Extension 1 – A Full Target Practice Experience
It would be nice to set up a full experience so the player can practice shooting. In
this extension, you can spawn some rabbits, arm your player with a bow and
arrows, and set the mode to survival. Track the shots your player takes.
Extension 2 – A Counter to Track the Number of Rabbits Hit
It might be nice to have a counter to track the number of rabbits you hit. Try using
the on mob killed block and change the animal to rabbit. This will use the same
logic as the arrow counter.
• Could you make a total misses counter?
• How else can you modify the code to make this the ultimate target practice?
Minecraft Survival worlds are full of high places. Let’s use an event handler and a
counter to come up with a useful postmortem report after you have fallen from a
high place. This death report will show how many blocks you fell before
respawning.
13
For this activity, you will create code so you are able to toggle back and forth
between creative mode and survival mode; you will fly up high to a point for
testing.
You will create a variable that keeps track of the distance you have fallen and you
will report that distance in blocks after you respawn. (slide 41)
After students complete the program, they should test their code. Enter into
creative mode (if not already) and fly up into the sky (i.e., double tap the space
bar). Once in the sky, switch to survival mode by entering “su” into the chat
window to fall back to Earth. After you die, select “respawn”. In the chat window,
enter “pm”. You will see a report of how many blocks you fell!
Coding Solution:
If time permits, have students try out the challenges and/or extensions.
Challenges
Challenge 1 – Let’s Report in Blocks
Can you figure out an easy way to print your fall report in blocks in the Minecraft
world? Do you think this might be easier to read than the small words in the in
chat window?
• Change the say block to something else.
• Can you figure out what block will allow you print this information in blocks?
Challenge 2 – Set Up a Variable to Track Total Fall Distance Over Multiple Falls
You can report your last fall, but what about reporting the total number of blocks
you fall over several jumps? If you fall 40 blocks and then 50 blocks, the total is 90
14
blocks. Entering “pm” would return “You fell 50 blocks”. Your new command “tot”
(total) will actually say, “You have fallen 90 blocks total so far. Keep jumping!”
• You will need a new VARIABLE to store the total fall distance.
• Use a set to add fall to this variable every time you die.
• Create a new on chat command. Rename it to “tot”.
• You need to use the join to put the entire message together like you did
before.
LESSON CONCLUSION
Upon completion of this lesson, students should be able to answer the following
questions: (slide 43)
15
The following questions can also be used as an exit ticket (formative assessment).
A printable version of these questions can be found in the Assessment Guide.
1. What are the two types of coding blocks you used to find out how many
blocks you fell in Falls in the Air?
Answer: Event handler and counter
2. What other things in Minecraft might be useful or interesting to use code
to count?
Answer: Answers will vary
Conclude the lesson by reviewing the concepts covered in Lesson B. (slide 44)
In this coding activity, students will use variables to show their creativity with
words. You will join two words together to create a compound word. By using
variables, you can store two words and then—in code—combine them. The cool
part will be spelling out your new word in Minecraft. (slide 48)
Have all students log into Minecraft: Education Edition. Students should continue
working in the same world from Lesson B. Directions for navigating to the previous
world can be found on slide 49.
16
https://minecraft.makecode.com/?ipc=1#tutorial:github:mojang/educationconten
t/CodingWithMinecraft/unit_4/lesson_C
• Step 1: Open VARIABLES and create 2 new variables named word1 and
word2. Add set item inside the on start block.
• Step 2: Click Advanced to see the TEXT toolbox category. Select the “ “
variable and place this inside the set item, replacing the number 0. You will
set this variable to a string.
• Step 3: Use the set item drop-down list to rename item to word1. Right-click
(or hold) set word1 and duplicate it. Place the new duplicate in the on start.
• Step 4: Go back to the second set word1 and change word1 to word2 from
the drop-down list.
• Step 5: Write two different words! Replace the empty “ “ with some text for
word1. Replace the empty “ “ with some text for word2.
• Step 6: Print word1. Rename the on chat command to “mix”. Drag a print
block inside to snap inside the on chat command mix block.
• Step 7: Put word1 inside print. Change the grass to Redstone ore.
Coding Solution:
17
Challenges
Now you can change some things to make your own different and unique
situations!
Challenge 1- Display a ‘+’ Sign to Make the Action Look like a Math Problem
You are doing “word math” in this activity so let’s complete the idea! Add a plus
sign to the left of the words at the top, just like you would if you were adding two
numbers.
18
Coding Solution:
19
Coding Solution:
20
Write some letters to birds with code. A random letter from the alphabet is printed
as you fly! The range should be 0-25. Why? That’s because this is zero-based… It
starts with 0 as the first position.
• How could you print only vowels?
• What other ways could you use a random variable and text to create
something?
Coding Solution:
21
Coding Solution:
LESSON CONCLUSION
Upon completion of this lesson, review the concepts covered in this lesson. (slide
59)
22
Then, students should take the quiz (found in the assessment guide). This is
intended as a low-stakes formative assessment tool to establish whether students
are prepared to take on the unit independent project.
Questions Answers
1. What is a number variable? This holds numeric data. Examples: a
person’s age, a player’s score, the year, etc.
2. What is a string variable? This holds a string of alphanumeric
characters. Examples: a person’s name, a
password, the day of the week
3. What is a Boolean variable? This only has two possible values: true or
false. Examples: Is it daytime? Is it
nighttime?
4. What is a position variable This is a special kind of variable that holds
called in Minecraft? three numbers that describe a specific
location in three-dimensional space. These
numbers are called the X, Y, and Z
coordinates.
5. How did you use coordinates By storing the player’s world position when
to help align the spacing of you started to print.
your floating compound
words?
6. Why is it good coding practice To make it easily recognizable—In a large
to give variables meaningful coding program, naming variables with
names? names you can easily identify makes finding
problems much easier.
Then provide students with a preview of the next lesson. (slide 60)
23
For this project, create an original MakeCode project that uses multiple variables of
at least two different types to keep track of information in Minecraft. You must also
find a way to use a chat command with a parameter. (slide 63)
Review the success criteria for the independent project. (slide 72)
Grading Criteria
VARIABLES
4 = At least three different variables are implemented in a meaningful way.
Variables are of different types (text, number, Boolean, and/or position).
3 = At least two different variables are implemented in a meaningful way. Variables
are of different types (text, number, Boolean, and/or position).
2 = At least one variable is implemented in a meaningful way OR variables are all of
the same type.
1 = No variables are implemented.
CHAT/PARAMETER
24
4 = Project incorporates a chat command that uses one or more parameters in the
enclosing code.
3 = Project uses a chat command with one or more parameters that are not used
by the code.
2 = Project uses a chat command but does not implement parameters.
1 = Project uses no chat command at all.
LESSON CONCLUSION
Upon completion of this lesson, review the concepts covered in this lesson. (slide
66.
25
EDUCATIONAL STANDARDS
CSTA Standards
• 2-AP-11 Create clearly named variables that represent different data types and perform
operations on their values.
• 2-AP-10 Use flowcharts and/or pseudocode to address complex problems as
algorithms.
• 2-AP-12 Design and iteratively develop programs that combine control structures,
including nested loops and compound conditionals.
• 2-AP-13 Decompose problems and subproblems into parts to facilitate the design,
implementation, and review of programs.
• 2-AP-19 Document programs in order to make them easier to follow, test, and debug.
ISTE Standards
• 1.4.c Students develop, test and refine prototypes as part of a cyclical design process.
• 1.5.a Students formulate problem definitions suited for technology-assisted methods
such as data analysis, abstract models and algorithmic thinking in exploring and
finding solutions.
• 1.5.c Students break problems into component parts, extract key information, and
develop descriptive models to understand complex systems or facilitate problem-
solving.
• 1.6.b Students create original works or responsibly repurpose or remix digital
resources into new creations.
26