Minecraft Modding For Kids For Dummies
Book image
Explore Book Buy On Amazon

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.


When you test this code, you see this scene.


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.


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.


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.


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


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.


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.

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

  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.

  6. Call creeper from the main function.

  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.


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


About This Article

This article is from the book:

About the book authors:

Sarah Guthals, Ph.D. is the CTO of ThoughtSTEM and has dedicated her life to coding education.

Stephen Foster, Ph.D. is the CEO of ThoughtSTEM, a company that teaches computer science to kids across America.

Lindsey Handley, Ph.D. is the COO of ThoughtSTEM and has hundreds of hours of experience as a classroom instructor for Minecraft based science and computer science classes.

This article can be found in the category: