arrow_back Descriptive Objects
In this add-on, you will code your program to describe items on the screen when the mouse-pointer hovers over them.
To start, click on the apparel sprite, and choose a costume that you’d like to describe.
This example uses the watch.
Click on the costumes tab, and you will see that the watch is the first costume in the project.
Click back to the scripts editor, and drag out an “if then” block from the control menu.
Next, drag out an “equals” block from the operators menu, and place it inside the “if-then” block.
Next, add a “costume number” block from the looks menu, and place it inside the first value of the “equals” operator.
This process is similar to what you did in the earlier videos.
Type the costume number that matches the costume you selected inside the second value of the equals operator.
In this example, the watch is the first costume.
This block stack now says “ If the costume number equals 1, then.”
Next, describe the costume you selected inside the if-then statement.
Drag out a “say” block, and place it inside this loop.
Describe the object any way you like.
This example says, “This watch was custom designed by Heather.”
Test this code by clicking the block stack.
Make sure that the costume on the stage is actually the costume that you just coded.
When you click on the block stack, the sprite says the message you typed.
Next, code the sprite to say this message only when the mouse pointer is touching the costume you selected.
Add another “if-then” statement from the control menu, and place it around the first “if-then” block.
Then, drag out a “touching” block from the sensing menu, and place it inside the newly added “if-then” block.
Change the dropdown option to “mouse-pointer.”
The code stack reads: “say ‘this watch was custom designed by Heather’ if it’s costume 1 and if it’s being touched by the mouse pointer.”
Test this by clicking on the code.
That’s because the first conditional checks if the mouse pointer is touching the costume only once.
Add a “forever” loop from the control menu around the code stack to make the code continuously check if the mouse pointer is touching the costume.
Now test it.
Add a “when flag clicked” event so this block stack runs when the flag is clicked.
Now it’s your turn.
Code your program to describe different costumes if the mouse pointer touches them.
Consider duplicating the code stack and editing the costume number and “say” block to describe other objects in your project.