Raspberry Pi For Dummies by Sean McManus; Mike Cook

Raspberry Pi For Dummies by Sean McManus; Mike Cook

Author:Sean McManus; Mike Cook [Cook, Sean McManus; Mike]
Language: eng
Format: epub
Tags: Computers, Systems Architecture, General, vl-nfcompvg
ISBN: 9781118554210
Google: OnGH3xzTnE8C
Amazon: 1118554213
Publisher: For Dummies
Published: 2013-03-14T17:34:47+00:00


Scratch is developed by the Lifelong Kindergarten Group at the MIT Media Lab. See http://scratch.mit.edu.

Figure 10-10: Adding sound effects to your sprite.

Creating Scripts

Clicking blocks in the Blocks Palette is one way to issue commands to Scratch, but you’re not really programming. If you have to click each block every time you want to run it, you’re doing all the hard work of remembering the instructions and the computer can only work as fast as you can click the blocks.

A program is a reusable set of instructions that can be carried out (or run) whenever you want. To start to create a program, you drag blocks from the Blocks Palette and drop them in the Scripts Area in the middle of the screen. Most blocks mentioned so far have a notch on the top of them and a lug on the bottom of them, so they fit together like jigsaw pieces. You don’t have to align them perfectly: Scratch snaps them together for you if they’re close enough when you release the mouse button.

You put your blocks in the order you want Scratch to run them, starting at the top and working your way down. It’s a bit like making a to-do list for the computer.

A group of blocks in the Scripts Area is called a script, and you can run it by clicking anywhere on it. Its border flashes white, and you’ll see the cat move around the Stage as you’ve instructed it to.

You can have multiple different scripts in the Scripts Area, so you could have one to make the cat walk left and another to make it walk right, for example. When you add multiple sprites (see Chapter 11), each sprite has its own Scripts Area and scripts there to control it.

If you want to tidy up the Scripts Area, you can move a script by dragging its top block. If you drag a block lower down in the script, it is separated from the blocks above it and carries all the blocks below it with it. If you want to delete a block or set of blocks, drag it back to the Blocks Palette on the left.

The moonwalk is the dance popularized by Michael Jackson where the dancer looks like he’s walking forwards, but actually moves backwards. Figure 10-11 shows an example script to make our cat moonwalk across the Stage. The first two lines in the script reset the cat to the middle of the screen, facing right. She tells us she loves to moonwalk and then lets out a little whoop like Michael Jackson, which she keeps up for the duration of the dance. The costume switch changes the position of the cat’s legs, and it then glides 150 units to the left. We close the speech bubble by using the Say block with nothing in it, and then switch back to the other costume, which makes the cat’s legs move back to their default position. Give it a go!



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.