how to create your first program

In this lesson we will get acquainted with the basic commands in Scratch: events and sensors. And we will show how beginners can create a simple program. The instructions are intended for children 7-8 years old and older.

Scratch is a visual environment that many children use to start learning programming. Here you can get acquainted with the logic of compiling a program, study concepts such as a variable, a loop, a conditional structure and much more.

A program in Scratch is created by connecting blocks – multi-colored bricks that are magnetized to each other and form a branch. In this tutorial, we'll explore the two main categories of commands in Scratch: events and sensors. We'll also create a small program for the character to see the blocks in action.

Lesson prepared by online programming school for children Pixel. At the end of the material you can find a video in which the teacher shows all the blocks and breaks down the mini-game.

Events in Scratch

Opening official website Scratch. In order to start learning, you can either create an account on the site (this will be needed to save the project) or download the environment to your PC. We have instructions by loading.

Environment Interface

Environment Interface

All Scratch programs start with blocks from the Events palette, indicated in yellow.

Events in Scratch are indicated in yellow

Events in Scratch are indicated in yellow

Let's look at a few commands from this category:

  1. Most often, the program is launched when the checkbox is clicked; to do this, you need to use the “When the checkbox is clicked” block.

  2. The “When the spacebar is pressed” block has the same functionality. It also has many other keys that, when pressed, will launch the program: for example, you can select arrows or letters. They can be seen in the block drop-down list.

  1. The “When sprite is clicked” block launches the program when the user left-clicks on the sprite.

  2. The event “When the background has changed to a specified one from the list” will launch our program if the background changes to a specific one.

  3. The block “When the volume (or timer) is greater than 10 (the last value can be changed)” will launch the program provided that the parameters of the timer (which starts when Scratch opens and is automatically restarted when the program starts) or volume (which is recorded by the microphone, built into the computer) will exceed a certain value.

  1. Message blocks are necessary so that at a certain point in the execution of one program we can launch another. That is, convey to her a message that it is time to launch.

  1. The “Send message” block sends a command to start another program, which starts from the “When I receive the message” block. We can create the message itself by clicking on “New message”.

  2. The Send Message and Wait block delivers the message and waits for the execution of another program that received the message to complete. Only then does the program from which it was sent continue.

Let's try to make sure that when you press the “Right Arrow” key, our character – Scratch the cat – goes to the right, and when you click on the “Left Arrow” button, he goes to the left. To do this, we will need the “walk 10 steps” block from the “Movement” palette, indicated in blue. We create two mini-programs: 10 steps in one direction and -10 steps in the other. Let's launch and check.

Sensors in Scratch

Now let's move on to the operation of the sensors. Just as a person can see the world around him or feel touches on his skin, a program can understand when a sprite touches another character or a certain color. Let's get acquainted with the main blocks from the palette.

Sensors in Scratch are indicated in blue.

Sensors in Scratch are indicated in blue.

  1. The Touch sensor detects whether the sprite is touching the mouse pointer, the edge of our scene, or another sprite.

  1. The Key Down sensor detects the use of a specific key on the keyboard.

  2. “Mouse Pressed” is a similar block, but refers to a touch with a computer mouse.

  1. The Color Touches sensor calculates whether a sprite is touching a specific color. To select a color, you need to click on the color box and adjust it manually, or use the eyedropper, pointing at the color that you want to repeat.

  1. The Color Touches Color sensor helps you figure out whether a specific color on a sprite is touching another color.

  1. The Mouse Pointer Distance block returns the distance from the sprite to the mouse pointer or other sprite.

  1. The “Ask and Wait” and “Answer” commands display a question from the sprite and a dialog box for our answer.

  1. The Mouse X and Mouse Y blocks store the coordinates of the mouse pointer.

  1. The “Cannot Drag” sensor is responsible for allowing the sprite to move when launched in full screen mode.

  1. The “Volume” and “Timer” variables store the volume and timer values, respectively.

Sensors don't work on their own; they need to be built into conditions or cycles. Let's look at how this works using a balloon animation as an example.

Let's add cat and ball sprites. Launch will work when you click on the green checkbox. We use touch sensors on the arrow buttons and message transmission blocks from the “Events” palette. When you click on the arrows, the hero will move 10 points along the X and Y coordinates, and when he touches the blue color (the ball symbol), he will transmit a message.

Program for a cat:

Let's add a program for the ball: after touching, the ball will float to the top of the screen. To do this, we will need the “Swim N seconds to point X and Y” and “Go to X and Y” blocks from the “Movement” palette (you can learn more about these commands from another lesson).

Video: event and sensor blocks in Scratch

Watch the video with a visual analysis of the lesson:

The material was prepared by the children's IT school Pixel. If you want to understand the capabilities of Scratch, come to our online courses programming for preschoolers and primary schoolchildren. Also see full video course on the basics of Scratch programming, it is available for free.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *