Step 3

The if statement


Next, add the code into your project as shown.

Here we see a new and very important programming tool called the if statement which, like some while loops, uses a conditional.

Remember, a conditional is something that is either True or False. For an if statementwhen the condition is True the code that is indented/tabbed will run. If the condition is False, this code gets skipped.

Here, we check to see if the block the player is standing on is a sand block. (The “==” means “is equal to”) If it is, we spawn a block of fire! If it isn’t we continue on with the rest of the loop.

Notice how the code inside the if statment has two indents. This is because it is in the if statement AND the while loop, if statements and loops can be nested inside each other as many times as they need to, this is why the indents are so important!

Also, notice how we still need to add a small pause with “time.sleep”. This ALWAYS needs to happen in our loop so it is outside of the if statement and we can see this because it is only indented once.

Running the code


Once we are done with this code, go ahead and test it out!

If done correctly, you should create fire whenever you walk on sand! If not, go back and double check all of your code.

Think of some ways you can improve or change this code. For example, you can make it so walking on grass also burns it. Another thing you can try is planting flowers as you walk on grass, or even turning water into ice as you walk over it. There are a lot of things you can do here!