Skip to main content

Control: conditions

Conditions are a type of blocks that evaluate something, and if it is true, then the blocks nested inside it are executed. They are available in the Control menu.

Add these blocks and test them by clicking on the flag. The green blocks are in the operators menu. The purple blocks in the Looks menu.

imagen.png

In these blocks it is verified that 2+3=5, and since it is true, then the cat says "The addition is ok". If you change the 5 to any other value, for example 6, the condition 2+3=6 is false, and the cat says "Hmmm, something is wrong."

Practical case

Let's create a program that will make the cat meow when it touches the edge of the stage. To do this, in the Sensing menu, we will use the Touching? block.

imagen.png

We will need the sound menu too.

imagen.png

Solution

First we have to create the blocks that check if we are touching the edge, and then meow:

imagen.png


A possible solution in the previous exercise for adding the edge touch check is to add it right after moving the cat in all directions. The option duplicate is perfect for this.

imagen.pngSensing blocks allow to add more interactivity with the user, with the block ask and wait. 

Practical case


Create a program that asks you your name, and then greet you saying "Hello" and your name, and then invite you to play with the dog.

Solution

We will use a system variable available in Sensing blocks called answer that stores the answer received, and the operator block to concatenate words in a text message.

imagen.png