Conditions in Blockly (Ages 5-8)

Hello everyone! In this activity, we’ll learn about conditions. Afterwards, you’ll know what conditions are, and how to create them in Blockly!

Before we begin:

  1. Make sure that you have your KINI robot, and that it is connected to the internet.KINI App Game Tab
  2. Open the app, and go to the Blockly tab by clicking the Blockly button in the bottom right corner. We will be using the two Repeat blocks to create our code.Kini App Blockly Tab
  3. Understand the basics of Blockly - if you don’t, make sure to visit the “Introduction to Blockly” activity before this one.

What is a condition?

  • A condition is something that must happen for something else to happen
  • In real life, you could say “One condition for you to do your homework is a quiet area” 
    • In this example, before you can do your homework, you must have a quiet area, which is the condition
  • Conditions can be used to control KINI in Blockly
    • KINI will only do a certain action if the condition happens

How to use conditions in Blockly:

  1. To find blocks that we use to make conditions, go to the light blue Logic tab on the left side of the screen. Conditional statement blocks are shown in the light blue Logic tab.
  2. For this example, we will use the “If/Do/Else” block. Click it for it to appear beside the two repeat blocks. The "If/Do/Else" block is shown beside the two Repeat blocks after clicking it.
  3. Drag the “If/Do/Else” block and snap it into place in the Repeat Forever block.

    • The Repeat Forever block is used for conditions, because we don’t just want to see if the condition happened one time, but always The "If/Do/Else" block is shown in the Repeat Forever block, after it was snapped into place.
  4. The condition goes into the "If" part of the block

    • To find condition blocks, go to the green Sensors tab. This example uses the distance sensor.The image shows block coding of the condition "If Kini's distance = 10 cm"
  5. The action that happens if the condition is true goes into the “Do” part of the block

    • To find action blocks, go to the orange KINI tab. This example uses a rotate left blockThe image shows block coding of the intstruction "If Kini's distance = 10 cm," do "Rotate Left 1 second."
  6. The action that happens if the condition is false goes into the “Else” part of the block

    • To find action blocks, go to the orange KINI tab. This example uses a move forward blockThe image shows block coding of the intstruction "If Kini's distance = 10 cm," do "Rotate Left 1 second," else "Move Forwards."
The code in the example tells us that the condition is that KINI is less than 10cm from an object. If that condition is true, KINI will rotate left for one second to avoid the object. If the condition is false, KINI will move forward. Since the entire block is in the Repeat Forever block, this will happen over and over, meaning that KINI will move around the room avoiding objects.

Congratulations everyone! You just learnt what a condition is, and how to use conditions in Blockly. You can try out this same code, and even try adding your own conditions to make it better!

 

Now that you’ve learnt about conditions, each time you code KINI try using conditions to solve problems. Good luck, and have fun coding with conditions!