In the previous lesson, we have learned about Motion, Looks and Sound commands. Also, we created a story in which we add 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.
Now with help of Arun and Raj, we will explore these commands.
Arun- Raj let’s start today’s topic on Events Commands.
Arun- First block isblock. This block helps us to run the command when we click on the green flag, above the stage area.
Raj- The program is running whenever I am clicking the green flag. That means I can run the program by clicking either on the script or on the green flag.
Arun- Correct! But there are other blocks also to run the program. Such thatblock. Here you can select any key from your keyboard which on pressing can run the program.
Raj- How Arun?
Arun- Drag block and place it above the fish script. Select the key of your choice.
Raj- I will select space bar.
Arun- Now press space bar.
Raj- Wow! My program is running when I am pressing the space bar.
Arun- This is how you can use any key from the key board. You can also run your program by clicking on the sprite.
Arun- Place block on the top of the starfish script. Click the starfish.
Raj- This is very interesting; my program is running. Now I know different ways to run the program.
Arun- There are other blocks also which will let you perform any task based on that event, the event can be loudness, background or any message.
Raj- Please tell me How?
Arun- Okay! Use block it will pick the volume of the sound that the computer microphone is picking up. Once the value is higher than the chosen amount, the script will begin to run.
Raj- How to use this block?
Arun- Drag block on the scripting area of starfish and place it there. Drag block and place it under the block and click on it.
Raj- A pop-up asking to use
Raj- The program is runs only when the value is greater than the given value.
Arun- Correct! Now move to next block .
Raj- how it will work?
Arun- let me show you.
Go to the fish sprite, drag out block and place it over the scripting area. Also drag out block from looks menu and place it below the block.
Raj- Done Arun!What next?
Arun- Now go to the starfish sprite and drag out two blocks and place it separately over the scripting area.
Arun- Next drag block and place it under first block. Also drag block with block from the looks menu and place them under the second block, select the backdrop 2 from the drop-down list.
Raj- Okay done.
Raj- Why we are using two blocks here.
Arun- To understand the concept more clearly. Now go to the fish sprite and click the script and go to the starfish sprite and click the first script.
Raj- Okay now I understand, as the code describes to hide the starfish when backdrop 1 is selected.
Arun- Correct! To understand more clearly, click on the second script.
Arun- Here the backdrop changes and if backdrop will change the starfish will show back in the stage area.
Raj- I totally got your point here. This looks very tough but on performing I am able to understand everything.
Arun- Good. Now move to the next blocks.
Raj- Why not!
Arun- and blocks are used to send message from one sprite to other.
Raj- How Arun?
Arun- Go to the fish sprite, drag block and place it over the scripting area. Then go to the motion menu and drag out the block and place it under the block.
Raj- Okay, What next?
Arun- Now go to the Starfish sprite and drag out the block and place it over there.
Raj- How can we write message in this block.
Arun- In the drop-down menu click on the new message and a pop-up appears to write the message.
Raj- Okay I write the message “Hello Fish!”.
Arun- Okay. Now click on the block.
Raj- The fish glides towards the starfish. But How?
Arun- This block broadcast this massage to the fish and block trigger the script to run.
Raj- That is why the fish glides towards the starfish.
Arun- Correct. There is one more block , which will first broadcast the message and wait until the other sprite’s script completes after that performs other tasks.
Arun- Replace block with block. Also go to looks menu and drag out block and place it under the block. Now click on it.
Raj- You are right. First, the fish glides towards the starfish and then the starfish said Hello!
Arun- Now you know so many ways to control your script. Next time we will learn about loops and conditions commands.