In the previous lesson, we learned about Motion, Looks and Sound commands. Also, we created a story in which we added different effects and sounds. In this lesson, we will learn about different event commands that will help us to trigger our script on particular events.
Arun: Raj, let’s start today’s topic on Event Commands.
Raj: Sure!
Arun: [when green flag clicked] runs the script when the green flag is clicked.
Raj: The program runs when I click the green flag.
Arun: Correct! Next, [when [space v] key pressed] runs the script when a specified key is pressed.
Raj: I’ll select the space bar.
Arun: Now press the space bar.
Raj: Wow! The program runs with the space bar too.
Arun: You can also run the script by clicking the sprite with [when this sprite clicked].
Raj: Clicking the sprite runs the program.
Arun: Use [when [loudness v] > (10)] to run the script based on sound volume.
Raj: The script runs when the sound is louder than the set value.
Arun: Next, [when backdrop switches to [backdrop1 v]] runs the script when the backdrop changes.
Raj: I see how backdrop changes can trigger scripts.
Arun: Use [broadcast [message1 v]] to send messages between sprites.
Raj: The fish glides to the starfish when the message is received.
Arun: Correct! [broadcast [message1 v] and wait] first broadcasts the message and waits until other scripts are complete.
Raj: The fish glides first, then the starfish says “Hello!”
Arun: Now you know several ways to control your script. Next time, we’ll learn about loops and conditions.