UnicMinds

What are Events in Scratch Programming?

Event Blocks in Scratch Programming

To make games, apps or websites, we need to understand a very interesting concept called “Events”. In this post, we will specifically learn about how to use “Events” in Scratch.

To understand events, let’s take an example.If you want to send a message to your friend, what will you do? 

  1. Press the power button on the phone.
  2. Scroll left and right to find the whatsApp 
  3. Tap on the contact to whom you want to send the message.
  4. Type the message
  5. Press the send button

What are Events in Scratch?

Exactly, “Events” are the actions that cause something to happen.

Step 1 and 2 in the above list are the actions that a user or person does to interact with the device phone.

Steps 3, 4 and 5 are the actions that a user or person does to interact with WhatsApp.

Let’s understand the events in games by taking a few examples in Scratch.

In Scratch, there is a section called Events which looks as shown below:

1.

The first event is When Flag clicked, which means the action here is clicking the green flag.

Let’s create a small game in which the cat should change color when the flag is clicked.

The event is clicking the green flag, the result of the event is that the sprite changes in color.

In the code above, the event green flag clicked leads to the start of the forever loop. When the green flag is clicked, the sprite will keep changing color

2. 

The second event is when any arrow keys or any key is pressed.

In the following example, the sprite moves left when the left arrow is pressed , moves right when the right arrow is pressed and so on.

3. 

The third event is when the sprite is clicked. The code below shows that when the sprite is clicked , the sprite starts spinning.

4. 

The fourth event is when the backdrop changes.

Add the following backdrops under backdrop as shown below.

The code shown below shows that when the flag is clicked, the backdrop changes to underwater2 after 3 seconds.

.

When the backdrop changes to underwater2, the sprite changes the size by 100 which makes the size to 200 as shown below.

5. 

The fifth event is broadcasting the message from one sprite to another. This event is used when one sprite sends a message to another sprite.

Lets understand this by using an example.

There are two sprites as shown below:

Let’s write the below code for the duck

Everytime the sprite is clicked, the number of clicks is increased by 1. There is an event of broadcasting a message win from the duck to the you win sprite when the number of clicks reaches 5.

Add the following code to the you win sprite

When the you win sprite receives the win message, the sprite should show as shown below.

Hope this is useful, thank you.

You may like to read: Block Coding Quiz, Scratch Coding Quiz, Introduction to Block Palette in Scratch & Parts of a Computer

BOOK A FREE TRIAL