Video – Events and Sprite Communication
When we create electronic games we often want some actions of the heroes to take place in the same time.
Also we want the different sprites we use to communicate with each other.
So games become more interesting.
You will find the answers to the above 2 issues in the upcoming video by Stevie.
Please watch carefully.
Events are the various events that can be made in the progress of the game we create and cause the execution of specific instructions, therefore also behaviors in the sprites of this game.
An event we have encountered in Scratch several times is the command: "when the green flag is clicked".
This instruction basically proceeds to execute the instructions that follow when the user clicks on the green flag, i.e. when he causes the specific event.
In addition to the specific events we have just mentioned, very important events we often use are the following
- When a specific button is pressed
- When you click on a specific sprite
- When a specific message is received.
It is important to say that when an event occurs, such as pressing the green flag, more than one piles of code can run.
Watch the scenario we will assign to one of the lions that chases the monkey, in the game we will create in the next lesson.
Notice that there are 2 piles of codes running when the green flag is clicked.
This code runs at the same time.
Very often there is a need for communication between the sprites of our game.
For example, in the game we talked so much about in this lesson, where the monkey chases bananas, let's assume that as soon as the player has accumulated 10 points, another character must appear, let’s say, Gas, and he will say the phrase "Congratulations you reached 10 points" and then he will disappear.
Let's see what we want to do in practice and then let's see how it happened (video follows)
Let's look at the solution to this problem. We'll need to use the 'Broadcast' command and the 'When I receive a message' command.
Soon we can say that once the points reach 10, the banana character (which measures the points) shows the message "10 points".
Any character can communicate messages.
Messages are streamed to all sprites.
In order for the sprite to hear this message, in our case Gas, it must dispose the event "When I receive the message".
Let's now see how we have achieved the appearance of the "Gas" object at the right time.