skip to content
Introduction to Coding

Activity

Lesson on Sensing Commands

In this lesson, we will learn about sensing commands with the help of Raj and Arun.

Arun: Hello Raj! Shall we start with the first sensing block?

Raj: Why not!

Arun: The [ask [What's your name?] and wait] and [answer] blocks are used together to display your answer on the screen. To display the answer, tick the check box in front of the [answer] block.

Raj: Okay! Can you explain how to use this block?

Arun: Sure! Drag the [when green flag clicked] block from the events menu and place it in the scripting area of the starfish sprite.

Arun: Also, drag out the [ask [What's your name?] and wait] block and place it below the [when green

flag clicked] block. Click the green flag.

Raj: On clicking, it is asking me to type an answer.

Arun: Whatever you write will display in the [answer] block.

Raj: This block helps in asking anything, like if we create a game, we can ask for the player’s name.

Arun: Correct! Next is the [set drag mode [draggable v]] block. This block makes the sprite draggable or not, selecting from the drop-down list.

Raj: How?

Arun: Drag out the [set drag mode [draggable v]] block into the scripting area of the fish sprite. Select the “not draggable” option from the drop-down list.

Raj: But the fish is still moving.

Arun: To see the change, go to full-screen mode where the fish is non-draggable.

Raj: Yes, Arun!

Arun: Now, our next blocks are [loudness], [timer], and [reset timer]. These blocks help us know the value of sound picked up from the computer’s microphone, the timer since the green flag is clicked, and resetting the timer.

Raj: But how to use these blocks?

Arun: Go to the sensing menu, and you will find checkboxes in front of the [loudness] and [timer] blocks. Tick those checkboxes.

Raj: These blocks are displaying the loudness and timer on the screen.

Arun: You can also reset the timer. Drag out the [reset timer] block and click on it.

Raj: The timer starts from 0 again.

Arun: There are other sensing blocks also, such as [current [year v]] and [username] blocks.

Raj: How to access these blocks?

Arun: Tick the checkbox in front of these blocks, and they will start displaying details on the screen.

Raj: How can they be useful?

Arun: The [current [year v]] block is useful where any condition must be satisfied related to the current time,

day, year, etc. And the [username] block displays the username of the programmer.

Raj: Okay. So the [days since 2000] block will display the days, but where can this block be useful?

Arun: This block can be useful for calculating time.

Raj: Oh, these blocks are very useful for making different games.

Arun: Here is the [([x position v] of [Sprite1 v])] operator block, which will let you know details about the stage or sprite.

Raj: This is an amazing block that will be helpful for performing actions based on the details.

Arun: You are right. We can use these details in conditional commands.

Arun: Now next is the [distance to [mouse-pointer v]] block. This block helps to know the distance between a sprite and the mouse pointer or another sprite.

Raj: How?

Arun: Click on the [distance to [mouse-pointer v]] block, and it will show you the distance between the

mouse pointer and the fish sprite.

Raj: Okay! To show the distance between two sprites, we have to select from the drop-down list.

Arun: Correct! And when you click on the block, it will show the exact distance.

Raj: What will the [mouse down?], [mouse x], and [mouse y] blocks do?

Arun: The [mouse down?] block tells if any of the mouse buttons are pressed. The [mouse x] and [mouse y] blocks let you know about the mouse’s X and Y coordinates.

Raj: How?

Arun: Drag out the [mouse x] block and place it in the scripting area of the fish sprite. Here you can see the use of the conditional loop block. Drag out the [wait until <mouse down?>] block and place it in the space provided in the [forever] block.

Arun: To perform any task, drag out the [glide 1 secs to x: () y: ()] block and place it between the [wait until <mouse down?>] block.

Raj: Here in the [glide 1 secs to x: () y: ()] block, we can change the values so that when this condition becomes true, the sprite will move to that position.

Arun: Correct! If you want to move the sprite with the mouse pointer, use the [mouse x] and [mouse y] blocks in the [glide 1 secs to x: () y: ()] block.

Raj: But the fish is not following the mouse pointer.

Arun: To see the movement,