How to Earn the Minecraft Functions Badge

By Sarah Guthals, Stephen Foster, Lindsey Handley

Here, you find out how to complete the Functions challenge in Minecraft and earn the Functions badge. To start, be sure that you have opened the Functions challenge by clicking on the badge.

By the time you reach the end, you will know how to define two new functions: creeper1 and creeper2. This is the final code that you write.

image0.jpg

When you test this code, you see this scene.

image1.jpg

Use the Perform Command block

In the Functions badge, the block named perform command performs the command that is in the text block for a certain player, as defined by the player block. This shows the perform command block, which summons a cow to you.

image2.jpg

Minecraft has a set of commands that you can run from inside the game. You can search the Internet for the term Minecraft commands to see millions of web pages that introduce them.

image3.jpg

For example, if you want to summon a cow without writing a mod, you can type the command /summon Cow in Minecraft to summon one.

image4.jpg

To make Minecraft run the perform command block, you have to place the block inside the main function.

image5.jpg

Test your code at this point, to make sure that it does what you want. When you run this code in Minecraft, you see a scene similar to this one.

image6.jpg

Create and call a new function

As you can see in the completed code for this challenge, you need to define two new functions. Define the first one and test your code to make sure it works. Then define the second one. If you finish writing your code without testing it, you make errors harder to find, because you’ll have lots of code to trace.

To create and then call the creeper function, follow these steps:

  1. Drag a function block into the programming environment.

  2. Click on the words do something and rename the function creeper.

    image7.jpg

  3. Add a perform command block in the creeper function and type summon creeper in the text area.

    image8.jpg

  4. Run your mod in Minecraft or the simulator.

    Notice that only a cow is summoned, not a creeper. The reason is that only the main function is called (from Minecraft or the simulator). You did not call the creeper function, so it’s ignored.

  5. When you view the Functions category, notice that a new block has been created — the creeper call block.

    image9.jpg

  6. Call creeper from the main function.

    image10.jpg

  7. Run your mod in Minecraft or the simulator.

    A cow and a creeper are summoned.

Trace function calls

To better understand what is happening when you run your mod, trace your code using paper-and-pencil.

To trace each line of code, follow these steps:

  1. The main function is called, and the first thing it does is run the perform command block that summons a cow, and that makes a cow appear, so draw a cow.

  2. The creeper function is called, so Minecraft looks into the creeper function. You should look at it too.

  3. When the perform command block that summons a creeper is run, it makes a creeper appear, so draw a creeper.

    The creeper function has no more lines of code, Minecraft looks back (and you do, too) to the main function.

    The main function has no more lines of code, so the code is complete.

Add a second Creeper function

In the same way you created the first creeper function, create the second creeper function. Step 3 in the Functions challenge gives you instructions on this task.

image11.jpg

If you need help, you can ask questions in the Comment area below the badge by clicking the Are You Stuck? link.

image12.jpg