0% found this document useful (0 votes)
15 views31 pages

8325548264145603-Coding With Minecraft - Unit 6 - Functions

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views31 pages

8325548264145603-Coding With Minecraft - Unit 6 - Functions

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

Educator Guide

Unit 6 – 4 Lessons
60 minutes per lesson
Single Student

Coding with Minecraft:


6- Functions

EDUCATION.MINECRAFT.NET
1
THEME OVERVIEW
In this unit, we’ll explore the coding concept of functions. Often in programming,
there are tasks or procedures that are used frequently within the same program.
Rather than rewrite the lines of code that perform a particular task each time you
need it, you can group that set of instructions together as a function. Grouping
frequently used instructions as a function makes your code more efficient. You can
write the set of instructions once as a function and from then on simply ‘call’ the
function from inside your program whenever you need that task done. A function
is usually given a name that describes the task it will perform when called, making
your code easier to read too!

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 Functions
• Lesson B: Coding with Functions
• Lesson C: Building on Functions
• Lesson D: Get Creative with Functions

LESSON OBJECTIVES
• Learn and apply the coding concept of functions
• Describe the different kinds of coding functions
• Explain the importance of functions in coding and while playing Minecraft
• Design an original project to apply the use of functions to create an
automated solution

THINGS TO KEEP IN MIND


• You will need to gather the additional materials for the unplugged activities:
Lesson A: Additional materials for the lesson:
o jar of peanut butter (initially closed). Check for allergies to peanuts.
You can always substitute butter or cream cheese for the peanut
butter.
o A jar of jelly (initially closed)
o A bag of sliced bread (initially closed)
o A plate
o A knife
o A paper towel

2
• Remind students that there may be more than one solution for each of the
activities.
• Students should keep a coding mindset. As with any other sport or activity,
you must practice in order to get better. Coding is no different.

MINECRAFT MECHANICS
C C
Summons the Agent and opens the MakeCode
interface
T T
Opens chat panel in Minecraft for commands to
be typed
ESC ESC
When a student wants to leave the game, leave
chat, or pause the game

CODING BLOCKS
Function
Lets you create a portion of code that you
can reuse in your program

KEY VOCABULARY
Function – block of organized, reusable code that is used to perform a single,
related action

LESSON ACTIVITIES
Lesson A: Introduction to Functions (Slides 1-25)
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 functions. (slide 1)

Today, we are going to learn about what are functions and how we use them not
only in real-life, but how they are used in Minecraft. (slide 2)

3
Review the lesson objectives (slide 3)

So exactly what is a function? (slide 4)


Often in programming, there are tasks or procedures that are used frequently
within the same program. Functions allow you to repeat code too, but they are
more powerful for organizational purposes.

Loops will repeat the code inside them for the number of times you ask. Functions
run the code inside them only once, but their power is that they can allow you to
reuse code anywhere you want. You can write the set of instructions once as a
function and from then on simply “call” the function from inside your program
whenever you need that task done. This is great because you need to edit in only
one place if you need changes in the future. Also, your code will be easier to read.
Consider the following two examples. Which one would you rather edit? (slide 5)

4
Both of the preceding examples do the same thing. The difference is when you use
functions, you only need to edit things once. If you want to change coordinates, for
example, or an animal you are spawning, you just make one change! Without
functions, you would need to make five changes. This makes testing and
debugging a lot easier.

Grouping frequently used instructions into a function makes your code more
efficient but also makes it easier to understand. Functions help you organize your
code so that it fits the problem you are coding for. A function is usually given a
name that describes the task it will perform when called, making your code easier
to read. You are able to divide up problems into smaller, more manageable pieces.

Let’s suppose you want to make code that drives a car. Using functions, you would
make one function for each part of driving. You can think about your overall goal
and use functions to help you plan. To drive, you need to turn on the car, sit, stop,
open the door, and do various other things like this. Each of these would be a
function.

In order to consider and think through the steps needed for code, individuals often
use pseudocode to help them think through the specific steps needed.
Pseudocode is a detailed, readable description of what a computer needs to do.
Instead of trying to write this out in code, we will write this in plain English. (slide
6)

5
So now that we have figured out the steps, let’s consider how this pseudocode
would then translate into a function. (slide 7-8)

Now, let’s practice this process with an unplugged activity!

Guided Instruction (Teacher Modeling; “We Do”)


Unplugged Activity: Peanut Butter & Jelly (slide 9)
Materials Needed: Index cards, pens/pencils, whiteboard, whiteboard markers
Objective: Practice using the concepts of variables to create a “hands-on” action
code

Imagine that a parent makes you lunch every day – wouldn’t it be nice to delegate
this task to a computer? Ask students to imagine a robot that would make them a
peanut butter and jelly sandwich (PB & J) every day. What are the steps involved in
making a peanut butter and jelly sandwich? Can they write a function that includes
all the steps necessary to make a yummy sandwich? (slide 10)

Write Pseudocode for Making a PB&J Sandwich (slide 11)


• Have students work in pairs to write pseudocode (English language
instructions) for making a peanut butter and jelly sandwich.

Execute the Instructions


• You, the teacher, will pretend you are the robot.
• Collect all the pseudocode instructions and choose one to perform. The one
with the least number of steps is usually a good one to start with, because
the students will have made some assumptions about what you, the robot,
know how to do.
• Follow the instructions as written. This is your chance to have some fun,
usually by following their exact instructions without using “what you know
they meant.”

AN EXAMPLE RUN:
• The first step is often “Open the bread.” Feel free to just rip open the bag of
bread, because their instructions did not say anything about untying the
knot or unclipping the bag opening.
• If the instruction is “Put two slices of bread on the plate,” you can put one
slice on top of the other, because that instruction did not specify how to
place the slices.

6
• If their next instruction is “Put peanut butter on one slice of bread,” you can
put the whole peanut butter jay on the bread slice, because they gave no
instructions about opening the jar first.
• If an instruction tells you to do something you simply cannot like “Use knife
to scoop out jelly” yet the jelly jar isn’t even open, you can just report a
“runtime error” and stop the program.

By the time you have gone through a few steps, or run a couple of programs to the
point where they produce an error, the students have gotten the idea that they
have left out important steps and also made assumptions about what functions
you already know how to perform, and they are asking for their papers back so
they can rewrite their pseudocode.

Rewrite Pseudocode into Functions


• Give them the chance to rewrite their MakePB&J functions and let them
know some smaller functions you already know how to perform. For
example, if they write “Open jelly jar” or “Take lid off of jelly jar,” tell them
you already know the OpenJar function, so they do not need to write “Grasp
lid tightly. Twist lid to the left…”
• Students will then start asking, “Do you know how to…?” to find out what
other functions you already know.
• Perform some of their revised functions. Some students are usually happy
to consume the results!

EXAMPLE FUNCTIONS
Main Program
MakePB&J function
• Open bread bag
• Remove two slices of bread
• Place each slice face down, side by side on the plate
• OpenJar Peanut butter
• OpenJar Jelly
• Pick up the knife
• Spread Peanut butter on one slice of bread
• Spread Jelly on the other slice of bread
• Put the knife down
• Pick up one slice of bread and lay it face down on the other slice of bread
• Wrap the bread in a paper towel

7
Helper functions
Open function
• Grasp the end of the bag with the opening
• Unclip the plastic holder
• Untwist the wrapping
• Reach in
OpenJar function
• Put one hand on the top lid of the jar and grasp tightly
• Put the other hand around the base of the jar
• Repeat until the lid is loose: twist your top hand counter-clockwise
• Remove the lid of the jar
Spread function
• With a knife, reach into the jar
• Scoop out contents
• Move the knife backward and forward over the bread until the knife is clean
• Repeat the previous three steps until the bread is completely covered

Challenges
Challenge 1 – Write a function for a task
Have each student choose a “simple” task, like tying a shoe or brushing their
teeth, and ask them to write in pseudocode a function to perform that task.
• Along with their pseudocode, each student should bring in whatever props
are necessary to perform their function
• Select a student’s pseudocode and give that function and the props to
another student to perform.
• After watching you the day before, the students are primed to follow the
instructions as written!
These exercises help students realize the value of functions to organize their
programs, and also how each function can itself include “calls” to smaller
functions.
Challenge 2 – A Cleaning Robot
• How might you program a robot to clean the house?
• Are there tasks that are common for all rooms of the house? (Vacuuming,
dusting)
• Are there tasks that are specific to certain rooms in the house? (Clean the
toilet, make the bed)
• Which tasks can you assign to functions? (pickUpStuff, dust, sweep, vacuum)
• How might you break up the overall task of cleaning a house into specific
functions? (cleanTheKitchen, cleanTheLivingRoom, cleanBathrooms, etc.)

8
Have students write two different examples for cleaning a room in the house by
using pseudocode.

Coding Activity: A Leap of Faith Mini Game (slide 12)


Import the Program:
https://minecraft.makecode.com/?ipc=1#tutorial:github:mojang/educationconten
t/CodingWithMinecraft/unit_6/lesson_A
Before you begin this coding activity, 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. After students have logged
into the platform, navigate to the Coding with Minecraft subject kit. (slide 13) Once
in the Coding with Minecraft subject kit, select Unit 6: Functions to begin the
lesson. (slide 14)

In this activity, you will create a simple mini-game that creates a tiny pool of water,
then transports the player to a little platform 64 blocks high where the only way
down is to jump and land in the pool of water. If you jump and miss the pool of
water, you lose. Luckily, you’ll build this mini-game in MakeCode by using
functions, so you can try again and again. (slide 15)

Your mini-game will have three parts: (slide 16)


1. Creating the pool of water
2. Creating the platform
3. Teleporting the player to the top of the platform

Steps for the Coding Activity: A Leap of Faith Mini Game (slides 17-19)
9
• Step 1: Click the Advanced tab on the Toolbox to display more Toolbox
categories.
• Step 2: In the FUNCTIONS toolbox drawer, click Make a Function button.
• Step 3: Name this function pool and click Ok.
• Step 4: Repeat the previous step to create two more functions named:
platform and teleport.
• Step 5: From PLAYER, drag on chat command onto the workspace. Rename
this on chat command to "play".
• Step 6: From FUNCTIONS, drag the three blocks call function pool, call
function platform, call function teleport into on start.

This will be our main program to start our mini-game. Hopefully, you can see how
functions help to organize our planning when coding. Now, let’s build out these
three functions.

Now, create the code to fill up the pool. (slide 20)

• From BLOCKS, drag fill with into pool. fill with will fill a three-dimensional
box from the first set of coordinates to the second set of coordinates.
• Using the drop-down menu in fill with, select a block of water.
• In fill with, enter the following values for the first set of from coordinates: (0,
-1, 0).
• In fill with, enter (2, -3, 2) as the second set of coordinates.

10
This will make a 3 x 3 x 3 pool of water that is located below our player’s feet.

After the pool is built, a platform will need to be built high in the sky. There’s no
need for a tower or a ladder - there’s only one way down! You want to create a
wooden platform that is slightly offset from the pool below so that you have at
least a chance of jumping off the right side of the platform and landing in the pool.

Independent Work (Teacher Support; “You Do”)


Students should take the time to finish the building out the code for the mini-
game. Students will need to create the code to build the platform and the code to
teleport their player. (slide 21)

Coding Solution:

Then, you will need to publish and import the program into Code Builder.

Step 1: Share your program. Step 2: Name the project, provide a


brief description, and select the
“Publish to share” button.

11
Step 3: Select the green “Copy link” Step 4: Inside Code Builder, select the
button. “Import” button.

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.

NOTE: If you used the Ctrl + C (or Command + C for


a Mac) to copy the link, you would then paste by
pressing Ctrl + V (or Command + V) to paste.

Now, we are going to return to our Minecraft world to try out our code. (slide 22)

Challenge 1: Halloween Platform Jump

12
Let’s make the jump a little more interesting. You can make it more dangerous by
changing the water to lava and spawning some monster around the pool. You
should equip your character with a weapon too.
See if you can:
1. Change the water to lava.
2. Spawn some monsters next to the pool.
3. Give your character a sword of some kind.

Make new functions that handle the preceding steps 2 and 3. You can call these
new functions Monsters and Sword. You will then need to call these new functions
from on start.

It seems like you would die every time. Is there a way to fix this? Maybe save your
character when you fall? You might add water or change the gamemode to make
the challenge better.

Challenge 2: On Bounce
Did you know you can bounce on slime?

Change water in the original activity to slime! Add a call to a function in a new
event, on player bounce. Your function can do whatever you want. The new code
would look like this with your idea added to the function:

Extensions
There are no rules for these extensions. See what you can come up with!

Extension 1- Bouncing Pigs


Jumping on slime allows your character to bounce. This code creates slime when
you enter slime in the chat window. Then you press the spacebar to jump and
bounce. Watch it rain pigs!

What other cool things could you make by using slime?


Notice how you have kind of a chain reaction as one function is called and then an
event fires and another function is called. Still, it is easier to read with functions!

13
Extension 2 - Bouncing, Lightning, and Zombie Pigmen
This code just takes things up another notch from the last experiment!

LESSON CONCLUSION
Upon completion of this lesson, students should be able to answer the following
questions: (slide 23)

1. How does making something a function save you time when editing?
Answer: You only need to edit changes in the future and the function will
change anywhere it appears in the program.
2. How is a loop different than a function?
Answer: A loop is a block of code to be executed a specified number of times. A
function is a grouped block of code to complete an action.

The following exit-ticket question can also be used as a formative assessment. A


printable version of these questions can be found in the Assessment Guide.

Make an ordered list of the functions you need to perform to exit the room once
class is finished.
Answer: Answers will vary; listen for the teacher to dismiss us, put my things away,
clean my desk, stand up, grab my backpack, walk to the door, etc.

Conclude the lesson by reviewing the concepts covered in Lesson A. (slide 24)

Provide a preview of the upcoming lesson. (slide 25)

Lesson B: Coding with Functions (Slides 26-43)


Direct Instruction (Teacher-Led; “I Do”)
Welcome back to Coding with Minecraft. We are going to continue to learn about
and practice using functions in our coding. (slide 26)

Review the lesson objectives. (slide 27)

Review the concept of functions covered in Lesson A. (slide 28)

Guided Instruction (Teacher Modeling; “We Do”)


Coding Activity: Zombie Pig (slide 28)

14
Import project from here:
https://minecraft.makecode.com/?ipc=1#tutorial:github:mojang/educationconten
t/CodingWithMinecraft/unit_6/lesson_B

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 30.

Create another mini-game that instantly transforms pigs into an army of Zombie
Pigmen to combat! If you spawn zombie pigs and cannot defeat them, you lose.
Luckily you’ll build out this mini-game in MakeCode by using functions so you can
try again and again. (slide 31)

Our mini-game will have three parts:


1. Creating the Zombie Pigs
2. Creating strange time lapses
3. Setting the gamemode & difficulty

Steps for Zombie Pig Mini-Game: (slides 32-35)


• Step 1: Click the Advanced tab on the Toolbox to display more Toolbox
categories. In FUNCTIONS, click the Make a Function button. Name this
function zombiepig and click “ok”.
• Step 2: Repeat the previous step to create two more functions name
atmosphere and setup.
• Step 3: From PLAYER, drag a on chat command block onto the Workspace.
Rename this on chat command to "play".
• Step 4: From FUNCTIONS, drag the three blocks call function setup, call
function atmosphere, and call function zombiepig into the on chat
command "play".

15
on chat command "play" will be the main code that starts your mini-game.
Now, let’s build out the three functions that will accomplish your goals.

Create the Zombie Pig (slide 36)


• From MOBS, drag a spawn animal block into zombie pig. Change the animal
by selecting Pig from the drop-down menu. Then change the position in the
Z coordinate to spawn a pig five blocks north of the player.
• Repeat step 9 to create another spawn block and place it below the first.
• Replace animal with a projectile lightning bolt.
• Enter the same coordinates used for the pig: (~0, ~0, ~-5).

The trick here is that if a pig is hit by lightning, it transforms the pig into a Zombie
Pigman! This is why you want to spawn both at the same coordinates (~0, ~0, ~-5).

Adjust Settings (slide 37)


You want the game to work automatically. After you enter play, the game should
start with everything set up so you have some crazed Zombie Pigmen to battle.

The first issue is the difficulty level of the game. The pig will not change into a
Zombie Pig if the game is set to Peaceful.

• From GAMEPLAY, drag a set difficulty to into setup.


• Adjust this new block so it reads set difficulty to 'peaceful'.

16
Next, you want to change the game mode for your player. Setting the gamemode
to Survival mode ensures that the Pigman will come after you! As soon as you hit
the Pigman, it will start to attack you back!

• From GAMEPLAY, drag a change game mode to into setup.


• Adjust this new block so it reads change game mode to 'survival'.
• Also, adjust the target so that it targets “yourself”.

Finally, fighting will be very difficult without a weapon. You can give yourself a
weapon to make the game more reasonable for your player. (slide 38)

• From MOBS, grab a give block and place it as the last block in
the setup function.
• You will need to target yourself and give yourself a sword or other weapon.
The example gives one diamond sword.

At this point, you can test your game!

By entering play in the chat window, the mini-game will start.

17
Adjust Time (slide 39)
The last step for this mini-game is to add visual effects by adjusting the time of
day. This will give the appropriate atmosphere that all zombies require. You will
add a time set block. You can find this by using the search bar or looking in
GAMEPLAY.

A Minecraft day lasts 24,000 ticks for 20 minutes of play.

By setting the game to midnight, you set the current time to the start of midnight.
Time set blocks are an easy way to make time move to a common part of the day.
Midnight is equal to 18,000 ticks (12:00 AM).
• From GAMEPLAY, drag a time set block into the atmosphere function.
• Adjust this to read time set ‘midnight’.

Go to Minecraft, enter t to open the chat, enter play, and then press Enter.
NOTE: If the time is not changing, make sure the always day option is not turned
on in the Settings.

Spawn additional Pigmen

After defeating a pigman, you want another pigman to spawn. You can create a
new pigman with the event on Mob killed. You will use the function call Pigman.

• From MOBS, grab a on animal killed event and place it on the Workspace.
• Adjust this block so that it is on monster zombie pigman killed.
• Add a call function zombiepig to this new event.

Coding Solution:

18
Then, you will need to publish and import the program into Code Builder.

Step 1: Share your program. Step 2: Name the project, provide a


brief description, and select the
“Publish to share” button.

Step 3: Select the green “Copy link” Step 4: Inside Code Builder, select the
button. “Import” button.

19
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.

NOTE: If you used the Ctrl + C (or Command + C for


a Mac) to copy the link, you would then paste by
pressing Ctrl + V (or Command + V) to paste.

Now, we are going to return to our Minecraft world to try out our code. (slide 40)

Coding Solution:

20
Independent Work (Teacher Support; “You Do”)
Challenges
Challenge 1 – Function to Keep Score
Put the following blocks in the code from the activity. If you put these blocks in the
correct places, your scoreboard should work!

Challenge 2 – Function to Randomize Position


Create a function that chooses a random position so the pigmen are not as
predictable.
You will need to:
• Create random numbers for X and Y coordinates and then store everything
into one variable. Going farther than 10 blocks away from your character
might make the game unplayable so you could use the default setting (0 -
10) for random number generation.
• Call this new function in the right place so pigmen are spawned in random
places.

Extensions
Try out this code and just have fun! If you can or just take note of what you see.
You might remember something later and you can use some of this code for a
future project.
Extension 1 – Lots of Pigmen and Lots of Lightning
The on chat command is actually a function. It is the most powerful function
because you can pass in variables. Passing in information to a function is super
powerful. Here you are able to do a lot with just this one on chat command
because it calls itself.
Use this code to start with. Can you figure out what it is doing?
Extension 2 – Flashlight

21
Combining events and functions can get some cool results. It is difficult to see at
night and you may want to know what you are standing on. This code calls a
function to test what you are standing on as you walk and returns a message if
you are standing on grass.

What else could you detect for?

This is similar to the work you will do for the artificial intelligence lesson in Unit 9.

LESSON CONCLUSION
Upon completion of this lesson, students should be able to answer the following
questions: (slide 41)

1. How did you adjust the time of day in the game?


Answer: By adding a time set block from the search bar or by looking
in GAMEPLAY
2. What is something you could add to your code to spawn more Zombie
Pigmen in an event?
Answer: A loop to call the function multiple times

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 would have happened if you set your pigs and lightning to different
coordinates in your zombiepig function?
Answer: The lightning would not strike the pig and transform it into a
zombie.
2. Name a real-life function where a small error would mean something
doesn’t happen in the correct way.
Answer: Answers will vary; e.g., baking a cake, building a model airplane,
reading directions to a test, etc.

Conclude the lesson by reviewing the concepts covered in Lesson B. (slide 42)

Provide a preview of the upcoming lesson. (slide 43)

Lesson C: Building on Functions (Slides 44-66)


Direct Instruction (Teacher-Led; “I Do”)
Welcome back to Coding with Minecraft. We are going to continue to learn about
and practice using functions. (slide 44)

22
Review the lesson objectives. (slide 45)

Create a tribute to a very popular food—the burger. This program uses functions
to create a mouth-watering creation with a few ingredients. This is the perfect
example for functions. Functions allow you to divide your big projects of code into
smaller, more manageable pieces. The construction of a burger can also be divided
in such a way. (slide 46)

You burger code will have five parts:


1. Creating the Bottom Bun
2. Creating the Meat
3. Creating the Lettuce
4. Creating the Tomato
5. Creating the Top Bun

Guided Instruction (Teacher Modeling; “We Do”)


Before you begin this coding activity, 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 B. Directions for navigating to the previous
world can be found on slide 47.

Coding Activity: Burger (slide 48)


Tutorial can be found here:
https://minecraft.makecode.com/?ipc=1#tutorial:github:mojang/educationconten
t/CodingWithMinecraft/unit_6/lesson_C

We will create the first part of the burger together. (slides 49-52)
• Step 1: Click the Advanced tab on the Toolbox to display more Toolbox
categories. In FUNCTIONS, click the Make a Function button.
• Step 2: Name this function bottomBun() and click “ok”.
• Step 3: Repeat the previous step to create four more functions names meat,
lettuce, tomato, and Top Bun.
• Step 4: From PLAYER, drag a on chat command block onto the Workspace.
Rename this on chat command to "burger".

23
• Step 5: From FUNCTIONS, drag the five blocks call function bottomBun, call
function meat, call function lettuce , call function tomato, and call function
topBun into on chat command "burger".

NOTE: The order of these function calls is VERY IMPORTANT.

on chat command "burger" will be your main program to start your burger build.
Now, you just need to fill in the individual functions.

Create the Bottom Bun (slide 53)


• From BLOCKS, drag a fill into bottomBun. Change the block by clicking Oak
Wood Planks from the drop-down menu.
• Enter the coordinates for the top bun with a starting position of (~3, ~0,
~3) and ending position of (~8, ~0, ~8).

24
Independent Work (Teacher Support; “You Do”)
Students should finish the rest of the code on their own. They need to complete
the remaining 4 parts to complete the burger. Then, they should import the
program into Code Builder and test the code. (slide 54)

Coding Solution:

25
Challenges
Let’s add more to the burger!
Challenge 1- Burger Plate
You should create a plate for the burger. To do this, include another function and
name it plate. Don’t forget to add a call to the plate function in on chat command
“burger”.
Challenge 2 – Circular Lettuce
Can you use the circle block to create more realistic lettuce?

Now you can change some things to make your own different and unique
situations!
Extension – Bat Cave
This code uses three functions. One function digs a cave. Another delays the code
to give you a chance to fly away because the last function creates a whole lot of
bats.

Add something fun to this. Can you think of an enhancement?

NOTE: In order for the cave function to work properly, you need to be standing on
the ground when you start the code.

LESSON CONCLUSION
Upon completion of this lesson, review the concepts covered in this lesson. (slide
55)

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.

26
Questions Answers
1. How does making something You only need to edit in one place if you
a function save you time when need changes in the future and the function
editing? will change anywhere in it appears in the
program.
2. How is a loop different than a A loop is a block of code to be executed a
function? specified number of times. A function is a
grouped block of code needed to complete
an action.
3. What is the difference A function is a self-contained set of
between a function and a instructions for performing a specific task
custom function? within a computer program. Most objects
have multiple functions associated with
them. A custom function is a function
created by the programmer (as opposed to
functions associated with objects). A custom
function usually has a specific purpose and
can be/is used in multiple places within a
program.
4. What is the difference A Helper function usually has a specific
between Main Code functions purpose and can be/is used in multiple
and Helper functions? places within a program. A Main Code
function is a self-contained set of
instructions for performing a specific task
that often includes several Helper functions.
5. Why is it good coding practice To make it easily recognizable—In a large
to give functions meaningful coding program, naming functions with
names? names you can easily identify makes finding
problems much easier.

Then provide students with a preview of the next lesson. (slide 56)

Lesson D: Get Creative with Functions (Slides 57-65)


Direct Instruction (Teacher-Led; “I Do”)
Welcome back to Coding with Minecraft. Today, we are going to have the
opportunity to demonstrate our new knowledge and skills about functions. (slide
57)

27
Review the lesson objectives. (slide 58)

In this unit, you learned how organizing blocks of code into separate functions
makes your code more readable and saves space. Functions generally contain
sections of code that go together logically and accomplish one thing. The
function’s name usually tells you what it does.

Functions can call other functions. Although functions in MakeCode do not accept
parameters, you can use an on chat command block to pass in a parameter. You
might pass in a number to affect what the function does. Also, you could update
the value of an existing variable and then any function can access that. (slide 59)

Guided Instruction (Teacher Modeling; “We Do”)


Now it’s your turn to practice using functions as you build something in Minecraft.
One of the first things to do in Minecraft is build yourself a house. Your house can
be decorated in different kinds of wood, use big windows to let in lots of natural
light, or be dark and dungeon-like with traps to catch unwary visitors. It could have
tall castle-like turrets or go several levels underground and blend in with the
natural landscape. You might also use the land around you to grow carrots and
wheat to feed yourself and the animals around you. Your house, and the grounds
around it, are a chance for you to express yourself.

For this independent project, build your dream house or build a replica of an actual
building in Minecraft. Either way, use functions to automate creating as many
different sections of the house as possible. You might start with creating a floor
command that creates a floor by filling blocks in a square area at your feet. Or, you
might have a carpeting agent that creates long carpet runners that run the length
of your house. How about a builder that can create a farm for you automatically?
(slide 60)

Review possible ideas for their Minecraft projects. (slide 61)


Some ideas for functions:
• Create carpet.
• Create the walls of a room.
• Create a decorative fountain.
• Create a castle turret.
• Level an area of terrain so you have a flat place to build.
• Create a swimming pool.
• Build different levels for a garden or house.

28
• Build a doorway.
• Dig a basement.

Review the success criteria for the independent project. (slide 62)
Come up with something original that meets the following criteria:
• Creates, or helps to create a building, temple, monument, or other piece of
architecture in Minecraft
• Provides at least three separate and distinct functions
• Includes descriptive names that represent what each function does

Independent Work (Teacher Support; “You Do”)


Coding activity: Independent project
Have all students log into Minecraft: Education Edition. Students are able to use
any template/world they wish for this project. After students complete the
independent project, they will be responsible for completing a Minecraft diary
entry.

Minecraft Diary Expectations (slide 63)


Compose a diary entry addressing the following:
• What did you decide to build? Why?
• Describe each of your three functions and what each of them does.
• What kinds of building tasks did you decide needed to be done by hand?
Why?
• Include at least one screenshot of your finished building or piece of
architecture.

Grading Criteria
FUNCTIONS
4 = At least three separate functions, logically separate and appropriately named.
3 = Two separate functions, logically separate and appropriately named.
2 = One function logically separate and appropriately named.
1 = No functions logically separate nor appropriately named.

CHAT/PARAMETER
4 = Project addresses all required elements effectively and efficiently.
3 = Project is missing 1 of the required elements or is mostly effective and efficient.
2 = Project is missing 2 of the required elements or is somewhat ineffective and/or
inefficient.
1 = Project is largely ineffective and/or inefficient.

29
LESSON CONCLUSION
Upon completion of this lesson, review the concepts covered in this lesson. (slide
64.

Preview the upcoming unit—Conditionals (slide 65)

30
EDUCATIONAL STANDARDS
CSTA Standards
• 2-AP-14 Create procedures with parameters to organize code and make it easier to
reuse.
• 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.

UK NATIONAL CURRICULUM: COMPUTING - KEY STAGE 3


• Understand several key algorithms that reflect computational thinking [for example,
ones for sorting and searching]; use logical reasoning to compare the utility of
alternative algorithms for the same problem
• Use two or more programming languages, at least one of which is textual, to solve a
variety of computational problems; make appropriate use of data structures [for
example, lists, tables or arrays]; design and develop modular programs that use
procedures or functions
• Understand how instructions are stored and executed within a computer system;
understand how data of various types (including text, sounds and pictures) can be
represented and manipulated digitally, in the form of binary digits

AUSTRALIAN F-10 CURRICULUM: DIGITAL TECHNOLOGIES – YEAR 7 AND 8


• (ACTDIP027) Define and decompose real-world problems taking into account functional
requirements and economic, environmental, social, technical and usability constraints
• (ACTDIP030) Implement and modify programs with user interfaces involving branching,
iteration and functions in a general-purpose programming language
• (ACTDIP029) Design algorithms represented diagrammatically and in English, and trace
algorithms to predict output for a given input and to identify errors

31

You might also like