top of page

Creating Else Statements with Command Blocks in Minecraft Education

Minecraft Education Edition is a powerful and engaging platform for educators to teach various subjects, from history to mathematics and computer programming. One fundamental concept in computer programming is conditional logic, which allows us to make decisions based on certain conditions. In Minecraft Education Edition, you can introduce students to conditional logic through the creative use of command blocks. In this blog post, we'll explore how to develop "else" statements using command blocks, making your educational experiences in Minecraft even more dynamic and interactive.


Understanding Conditional Logic

Before we dive into the world of command blocks and "else" statements, let's quickly recap conditional logic. In computer programming, conditional statements are used to make decisions based on specific conditions. The most common types of conditional statements are "if" statements and "else" statements.

  • "If" statements execute a block of code when a specified condition is true. For example, if it's raining, wear a coat.

  • "Else" statements complement "if" statements. They allow you to specify an alternative action to take when the condition is false. For instance, else, wear a hat.

In Minecraft Education Edition, we can simulate this logic through command blocks to create dynamic gameplay experiences. The examples below are best supported by the development of prior knowledge taught in the Learn to Code with Commands program.


Scenario One: Comparing Two Blocks

Scenario Two: Checking for a player

Scenario Three: Checking for an item on a player

Scenario Four: Execute Unless

Scenario Five: Execute IF and UNLESS

Scenario Six: Execute Block State

 

Else Statement Scenario One: Comparing Two Blocks


We want a player to make a decision between placing a block or gold vs a block or diamond. Once they place the block, they press a button, and their decision will result in one of two different results.


Our first statement will be as follows:

ON a button is pressed, IF the test for a gold block is TRUE, THEN teleport the player to the green zone.

Command Block Else Statements in Minecraft

Our second line will then state:

ELSE, IF test for a diamond block TRUE, THEN teleport the player to the red zone.

Command Block Else Statements in Minecraft

There is also an additional statement that occurs in this algorithm which is

ELSE, do nothing.


Command Block Else Statements in Minecraft

Jump to this example 👇Command Block Else Statements in Minecraft


 

Else Statement Scenario Two: Checking for a player


In this example, a player will receive a title message if they are within a particular zone; otherwise, they will receive a different message.


Our full statement will be:

If a player is within a radius of 5 blocks, THEN display a title message WELCOME, ELSE display a title message BYE.

Our first statement will be as follows:

Command Block Else Statements in Minecraft

The ELSE statement in this example is then triggered by an inverted Redstone Torch:

Command Block Else Statements in Minecraft

Command Block Else Statements in Minecraft

Jump to this example 👇Command Block Else Statements in Minecraft


 

Else Statement Scenario Three: Checking for an item on a player


This time we want to check if a player has an item. This is a classic gameplay whereby we are asking a player to retrieve something first before moving on.


Our full statement will be:

ON a player presses a button, IF the player has an apple, teleport them to the green zone, ELSE teleport the player to the red zone

Our first statement will be as follows:

Command Block Else Statements in Minecraft

The ELSE statement is then simply triggered by a teleport command.

Command Block Else Statements in Minecraft





This algorithm essentially runs both teleport commands; however, if the player has an apple the teleport command to the green zone will take precedence.


Command Block Else Statements in Minecraft


Jump to this example 👇Command Block Else Statements in Minecraft