Manhasset Secondary School



Computer Applications 7 Mrs. Scharf

Miscellaneous

Scratch Techniques

Table of Contents

Repeat and Forever Loops

If-else loop

Nested if-else loop

Variables

Broadcast Command

Pen Tool

Lists

Concatenation

Repeat and Forever Loops (Control tab: repeat loop, forever loop)

Click here to go back to Table of Contents

These loops will make your sprite do a task as many times as you want.

Right now the cat is moving and playing sounds.

The repeat loop will make him do this sequence as many times as you specify. I put in 3 times.

The forever loop will make him do this sequence until you click the red stop button.

Costumes (Looks tab: next costume)

Your sprite, or character, can have different costumes. The costumes can make him look different, or make him look like he is moving.

Movement

Scratch has some sprites with different costumes already. You can also make your own.

To get a new costume, go to the costumes tab of the sprite you are working on. Click Import.

Find the sprite

You now have another costume for your sprite. Repeat until you have all the costumes you want.

Now you have to write the script. Use the “next costume” in the looks tab. I put a wait tab between costume changes and a repeat loop as well.

Click here to go back to Table of Contents

Questions and Answers (Control tab: if-else loop, nested if-else loop, Sensing tab: ask, answer Operators tab)

Click here to go back to Table of Contents

If-else loop (one correct answer)

From the Sensing tab, pull out an ask block and fill in your question. I asked, “What is the capital of Spain?

You want the person to know if s/he got the right answer. We will get an if-else loop from the Control tab.

Slide the question above the loop. We now need to fill this “hole”.

Go to the Operators tab. Choose the item the arrow is pointing to and drag it into the hole.

Go back to the Sensing tab. Drag the answer block into the first space.

Type Madrid in the second space.

Now you need to inform the user if the answer is right or wrong.

Go to the Looks tab and drag a say block into the space under the if block.

Replace the text with, “That’s right!”

Drag a second Say block under the else block. Have it say, “Sorry, the answer is Madrid.”

Go to the control tab and put a “When Green Flag clicked” block. Try it out!

Click here to go back to Table of Contents

Click here to go back to Table of Contents

Nested If-Else Loop-use this when you can have several acceptable answers.

Have the cat ask, “What would you like for dessert?” There are many acceptable answers. We will consider some popular answers like, ice cream, cake and cookies, and then account for other answers.

Let’s get the first if-else loop. Set it up exactly the way you normally do.

Now things get different! In the else portion of the loop, Get another if-else loop.

To save time, you can copy and paste the loops.

You will have one else portion left over. That is where the cat will say something like, “Oh, that’s a good choice, too!”

[pic]

Click here to go back to Table of Contents

Variables Click here to go back to Table of Contents

Let’s say I want to keep track of how many answers a person gets right.

Go to the Variables tab. Click on Make a variable.

Name it Number Right. Leave it for all sprites. Click OK

The variable is showing. You can hide it by unchecking the box.

We want to set the variable to 0 every time the program starts. Drag the “set number right to 0” block right after the “when green flag checked block.”

We only want the variable to increase when the person gets the answer right.

Drag “change number right by 1” block after the “say That’s right!” block.

Click here to go back to Table of Contents

Click here to go back to Table of Contents

Broadcast Command (Control Tab)

The Broadcast command can be used to communicate between two sprites, or a sprite and the stage.

Here is what I want to do: When the person gets the right answer, the stage looks different.

I started by creating a new costume for the stage in paint.

I named my new costume Yippee

Go back to the script for the cat. Insert a broadcast command where shown.

Click the arrow and select “new…”

Put Yippee in the space. Click OK.

You now need to go to the script for the stage.

Drag the “When I receive Yippee” block

Drag the “switch to background Yippee” under the broadcast block.

You want to make sure you start with the white background when the program starts.

Drag a “switch to background” block. Make sure you change it to background1.

Drag a “When green flag clicked” block on top. Try it out!

Click here to go back to Table of Contents

Pen Tool Click here to go back to Table of Contents

You can write or draw a picture with the Pen tool.

A sprite must operate the pen. If you want it to be invisible, you can make a dot the same color as your background.

Delete your Cat Sprite

We will make a dot with a white background the new sprite.

Fill the circle with white so it blends in with the white background.

I will be drawing an X. I need to position the sprite in the starting position.

Go to the Motion section, drag a go to block in the script area and put in the proper coordinates.

Go to the Pen section. Set your pen size and color. Then drag a pen down block.

Go back to the Motion area. Drag a glide block. Put in the same x and y coordinates, but change the sign. You will now be able to draw the first part of the X. Go back to the Pen area and put in a pen up block.

I am now going to draw the second part of the X. Notice I’m using the same x and y coordinates, but I change the signs depending on which quadrant I’m in.

I place a clear block (Pen area) to clear the screen every time I start the program, and a When Green Flag clicked (Control area) at the top of the stack.

Click here to go back to Table of Contents

Lists (Variables area) Click here to go back to Table of Contents

I want my sprite to say a variety of things. I will put all the possible things s/he can say in a list.

Go to the Variables area and click “Make a List”

Name the list and click OK.

It is now empty, but we will fill it up. Notice we have blocks to work with now.

Drag an add thing to Things to say block into the script area.

Put in something you want your sprite to say. Repeat until all the items in your list are entered.

Click on the stack in the script area. The items are now entered on the list.

Move the stack down so that you have room for your script.

Drag an item 1 of Things to say block into the script area. Change the 1 to any.

Now go to the looks tab and drag a say Hello for 2 secs tab.

Connect the two. Click on the tab and see that the phrase changes each time you click on it.

Go back to the Variables area and uncheck the list. It won’t show.

I finished this off with a forever loop and a When green flag clicked block.

Click here to go back to Table of Contents

Concatenation Click here to go back to Table of Contents

When you concatenate, you join two blocks of code together to form a longer block of code.

When we made the list, we concatenated.

Go to the Sensing Tab. Add an ask block to the screen.

Go to the Looks tab. Drag a say block to the screen.

Go to the Sensing tab and drag an answer block to the screen.

Go to the operators tab and drag a join block to the screen.

Drag the join block into the white box the word “hello” is in.

Drag the answer block into the white space that says world.

Type in, “It’s great to meet you, ” in the space that says hello. Make sure you put a space after the ,. When you run the program, the cat will ask you for your name…

…and then use it in his answer!

Using Concatenation instead of Nested If-Else Loops

A triangle can have 3 or three sides:

Get an if-else loop from the control tab:

Two answer blocks from the sensing tab:

And one “or” block and two “=” blocks from the operators tab.

Put one answer block in each of the “=” blocks

Put each of those blocks in the “or” block

Fill in the blanks with the possible answers, and put the “or” block in the if-else loop

Complete your if-else loop with the response for correct answers and the response for incorrect answers.

-----------------------

Name:_________________________________ Team:__________________________________

Name:_____________________________________ Class:____________________________________

Put loop in this space

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download