In the previous lessons, we learned about Motion, looks, sounds, events, and control commands. In this chapter, Arun and Raj will explore sensing commands.
Arun- Hello Raj! Should we start with the first sensing block?
Raj- Why not!
Arun-and blocks are used together and display your answer on the screen. To display the answer, tick the check box in front of theblock.
Raj- Okay! Can you explain how to use this block?
Arun- Sure! Drag the block from the events menu and place it in the scripting area of starfish.
Also, drag out block and place it below the block. Click the green flag.
Raj-On clicking it is asking to type an answer.
Arun- Whatever you wright will display in answer.
Raj- This block helps in asking anything, like if we create a game, we can ask for players name.
Arun- Correct! Next is block. This block makes the sprite to be draggable or not, selecting from the drop-down list.
Arun- Drag out block on the scripting area of fish sprite. Select the Non- 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 fish is non-draggable.
Raj- Yes Arun!
Arun- Now our next blocks are , and blocks. These blocks help us to know the value of sound picking up from the computer’s microphone, Timer since the green flag is clicked and resetting the timer.
Raj- But how to use these blocks?
Arun- Go to the sensing menu, you will find checkbox in front of and blocks, tick those check box.
Raj- These blocks displaying the loudness and timer in the screen.
Arun- You can also reset the timer. Drag out block and click on it.
Raj- The timer starts from 0 again.
Arun- There are other operator blocks also such as and blocks.
Raj- How to access these blocks?
Arun- Tick the checkbox in front of these blocks, they start displaying details in the screen.
Raj- How they can be useful?
Arun- The block is useful where any condition must be satisfied related to current time, day, year etc. And block is to display username of the programmer.
Raj- Okay. So block will display the days but where this block can be useful?
Arun- This block can be useful for calculating time.
Raj- Oh these blocks are very useful to make different games.
Arun- Here operator block, which will let you know details about stage or sprite.
Raj- This is an amazing block, which will be helpful to perform actions based on the details.
Arun- You are right. We can use these details in conditional commands.
Now next is block this block help to know the distance between sprite and mouse pointer or another sprite.
Arun- Click on the block, it will show you the distance between mouse- pointer and the fish sprite.
Raj- Okay! To show the distance between the 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 , and blocks do?
Arun- block will tell if any of the mouse button is pressed. and blocks will let you know about the mouse’s X and Y coordinates.
Arun- Drag out the block and place it on the fish script area. Here you can see the use of conditional loop block. Drag out the block and place it in the space provided in the block.
Arun- To perform any task drag out the block and place in between the block.
Raj- Here in block, we can change the value so that when this condition become true the sprite will move to that position.
Arun- Correct! If you want to move the sprite with mouse-pointer, useand blocks in block.
Raj- But the fish is not following the mouse-pointer.
Arun- To see the movement use block and place it below the block. Click the green flag.
Raj- Now the fish is following the mouse-pointer.
Arun- Let’s move to next block . This operator block is true only when the selected key is pressed.
Raj- We can use any key from the keyboard.
Arun- Yes! Select any key from the drop-down list.
Now drag out the block and place it on the fish script area. Here you can see the use of conditional loop block. Drag out the block and place it in the space provided in the block. Also drag out block from motion menu and place in between the block, change the values of x and y coordinate. To see the continuous movement use block.
Raj- On clicking the green flag, the fish move to given position when selected key is pressed.
Arun- Next operator block is block. This condition is true when sprite is either touching mouse-pointer or another sprite.
Raj- It will be used same as previous blocks, with conditional loop?
Arun- Yes Raj. Place the blocks as shown.
Raj- On clicking the green flag, whenever mouse-pointer touches the fish, it reacts accordingly.
Arun- Similarly, on touching any color the condition becomes true and starts the loop.
Arun- Using block, just place this block in the place of block.
Raj- I want the color to be same as another sprite, starfish.
Arun- For that click on the color in block, this will open a color pallet and select the drop-fill option which will let you select the desired color.
Raj- By this I can select any colour from the screen.
Arun- Yes. As you selected your colour now click on the green flag.
Raj- When the fish touches the starfish, it performs the certain action.
Arun- There is one more block, which will help to select the accurate color from current sprite to be touching to which color from the screen.
Raj- Which block?
Arun- block, in this the first color is of your current sprite and second color is of another sprite or anything in the screen.
Raj- Can I replace the block with block in previous script to see its working.
Arun- Select your colors and click on the green flag.
Raj- It is doing the same as you told. I have learnt so many things that I can start to make many games and stories using Scratch.
Arun- Then start doing that! There are other commands left which we will be discussing in further lessons.