In this lesson, we will learn about control commands with the help of Raj and Arun.
Raj: Hello Arun. You told me that next time we will learn to control the scripts.
Arun: Yes! With control commands, we will be controlling the scripts.
Arun: Let’s start with [create clone of [myself v]] and [when I start as a clone] blocks. Go to the starfish sprite and drag out the [create clone of [myself v]] block and place it in the scripting area. Select “fish” from the drop-down list.
Arun: Next, go to the fish sprite, drag out the [when I start as a clone] block, and place it in the scripting area. Also, drag out [move
(10) steps] block from the motion menu and place it under the [when I start as a clone] block.
Raj: Okay done!
Arun: Now go to the starfish script and click on it. What do you observe?
Raj: A clone of the fish is created and moves.
Arun: Correct! These blocks create a clone and trigger the script. If you want to delete the clone, use [delete this clone] block under the fish sprite script.
Raj: On clicking the starfish script, no clone is created.
Arun: Correct! The clone is deleted immediately after creation.
Arun: Move to the [repeat (10)] block.
Raj: What does it do?
Arun: Drag out [repeat (10)] block and place it between [when I start as a clone] and [move (10) steps] blocks. Click on the starfish script.
Raj: The fish moves 10 times.
Arun: Yes! If you want the sprite to move continuously, use the [forever] block.
Raj: How?
Arun: Replace [repeat (10)] with [forever] block. Click the starfish script.
Raj: The clone is moving continuously but goes out of the stage. What should I do?
Arun: Use the [if on edge, bounce] block from the motion menu.
Raj: Place the [if on edge, bounce] block below the [move (10) steps] block. Now click on the starfish script.
Raj: Now the clone is moving continuously and bounces back when touching the edges.
Arun: The clone is moving very fast. To slow it down, use the [wait (1) seconds] block.
Raj: How to use it?
Arun: Drag out the [wait (1) seconds] block and place it between [move (10) steps] and [if on edge, bounce] blocks.
Raj: Now the clone is moving slowly.
Arun: To stop everything, use the [stop [all v]] block below the [when I start as a clone] block.
Raj: The clone is created but deleted at the end of the program.
Arun: Yes, you are right.
Raj: These are amazing blocks. Now we can control sprites using these blocks.
Arun: There are more blocks like [if <condition>], [if <condition> then] [else], [repeat until <condition>], and [wait until <condition>].
Raj: How do they control the sprites?
Arun: I will explain these when we learn about sensing or operator commands because they need conditions to perform their functions.
Raj: Okay!
Arun: That’s all for this lesson. Next, we will discuss Sensing commands, where you’ll understand the remaining commands.