Conditionals are the part of a program that tells a computer when to perform a certain action.
An important part of programming is telling the computer WHEN to perform a certain task. For this, we use something called ‘conditionals’, because a certain condition or rule has to be met before an action is performed.
You’re already familiar with the concept of conditionals in your daily lives. Have you ever heard your parent say any of the following?
“If you clean your room, you can go out with your friends.”
“If your homework is done, you can play video games.”
“If you do your chores all week, you get your allowance, or else you are grounded.”
These are all conditionals! Conditionals follow the format of IF this, THEN that. (Sometimes the THEN is implied.)
IF (condition is met), THEN (action performed)
Another format for conditionals is IF this, THEN that, ELSE something else.
IF (condition is met), THEN (action performed), ELSE (different action performed)
Types of conditions in MakeCode
MakeCode for Minecraft features a conditional block called an IF… THEN… block.
There is also another related block called the IF… THEN… ELSE… block.
These blocks are in the LOGIC Toolbox drawer. These blocks will check to see if a certain condition is true, and if so, then they will perform their operations.
If you select the little plus sign at the bottom of these blocks, you can add more conditions.
By default, IF statements have a hexagon that says “true” in them when you first place them. If you don’t change this, then anything that the “If… Then…” block encloses will run every time because “True” is always true, like the example on the left.
In the example below, they represent the player’s exact location. This is always going to be false because the player is standing there, so there cannot be a block where its head or body is.
However, you can specify ~0 -1 ~0 to check the block the player is currently walking on, or even use a Position range to detect the presence of a certain block within a given area.
This activty uses an If..else block seen on the left
Answer the following questions
What Minecraft problem did you decide to solve? What does your program do?
How did you use conditional statements in your project?
Discuss one (or more) ways that working with a partner was different from just doing the project by yourself.
Describe one point where you got stuck. Then discuss how you figured it out.
Include at least one screenshot of your agent in action.
Share your project to the web and include the URL.
Note: If you decided to improve one of this unit’s coding activities, please talk about the new code you wrote in addition to what was already provided.
RUBRIC BELOW:-