<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Scratch Beginner&#039;s Guide &#187; Scratch Tutorial</title>
	<atom:link href="http://www.scratchguide.com/category/scratch-tutorial/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.scratchguide.com</link>
	<description>A Scratch Tutorial by Michael Badger</description>
	<lastBuildDate>Thu, 29 Jul 2010 02:16:30 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Click Me</title>
		<link>http://www.scratchguide.com/click-me/</link>
		<comments>http://www.scratchguide.com/click-me/#comments</comments>
		<pubDate>Tue, 25 May 2010 03:09:12 +0000</pubDate>
		<dc:creator>Michael Badger</dc:creator>
				<category><![CDATA[Scratch Tutorial]]></category>

		<guid isPermaLink="false">http://www.scratchguide.com/?p=200</guid>
		<description><![CDATA[Here&#8217;s a simple project that I started to demo Scratch for the June 2010 issue of LinuxPro Magazine. The game was inspired by the Click Me Challenge. It demonstrates, costumes, broadcasts, backgrounds, random numbers, operators, and gravity.
You can pick up a copy of LinuxPro Magazine at a bookstore near you. Now for the game. Click [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.scratchguide.com%2Fclick-me%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.scratchguide.com%2Fclick-me%2F" height="61" width="51" /></a></div><p>Here&#8217;s a simple project that I started to demo Scratch for the June 2010 issue of <a href="http://www.linuxpromagazine.com">LinuxPro Magazine</a>. The game was inspired by the <a href="http://www.scratchguide.com/anyone-can-a-make-game-even-you/">Click Me Challenge</a>. It demonstrates, costumes, broadcasts, backgrounds, random numbers, operators, and gravity.</p>
<p>You can pick up a copy of LinuxPro Magazine at a bookstore near you. Now for the game. Click the image below to play the game at the Scratch website and download the source.</p>
<p><a href="http://scratch.mit.edu/projects/mike_b/943286"><img src="http://scratch.mit.edu/static/projects/mike_b/943286_med.png" alt="Scratch Project" width="425" height="319" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.scratchguide.com/click-me/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Scratch Tutorial &#8211; Lists, mod, if-else</title>
		<link>http://www.scratchguide.com/scratch-tutorial-lists-mod-if-else/</link>
		<comments>http://www.scratchguide.com/scratch-tutorial-lists-mod-if-else/#comments</comments>
		<pubDate>Fri, 06 Nov 2009 02:25:02 +0000</pubDate>
		<dc:creator>Michael Badger</dc:creator>
				<category><![CDATA[Scratch Tutorial]]></category>
		<category><![CDATA[broadcast]]></category>
		<category><![CDATA[if/else]]></category>
		<category><![CDATA[lists]]></category>
		<category><![CDATA[mod]]></category>
		<category><![CDATA[sample chapter]]></category>
		<category><![CDATA[variables]]></category>

		<guid isPermaLink="false">http://scratchguide.com/book/?p=22</guid>
		<description><![CDATA[This is chapter 7, Games of Fortune, from the book Scratch 1.4: Beginner&#8217;s Guide.
 
In Scratch it is easy to create projects that
incorporate dynamic information using variables. However, variables
have a limitation; they store only one value at a time. Sometimes, we
want a variable to store multiple values.
Welcome to lists. In Scratch, a list allows us [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.scratchguide.com%2Fscratch-tutorial-lists-mod-if-else%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.scratchguide.com%2Fscratch-tutorial-lists-mod-if-else%2F" height="61" width="51" /></a></div><p>This is chapter 7, Games of Fortune, from the book <em>Scratch 1.4: Beginner&#8217;s Guide</em>.</p>
<blockquote><p><em> </em></p>
<p><em>In Scratch it is easy to create projects that<br />
incorporate dynamic information using variables. However, variables<br />
have a limitation; they store only one value at a time. Sometimes, we<br />
want a variable to store multiple values.</em></p>
<p><em>Welcome to lists. In Scratch, a list allows us to associate one list<br />
(a variable) with multiple items or values in much the same way we<br />
create a list before going to the grocery store. In this article, we will take a trip to the fortune-teller to demonstrate lists, and you&#8217;ll learn how to:</em></p>
<ul>
<li><em>Store and retrieve information in lists</em></li>
<li><em>Add and remove items from the lists</em></li>
<li><em>Keep track of items in a list by using a counter</em></li>
<li><em>Identify intervals using the <strong>mod</strong> block</em></li>
<li><em>Use if/else control blocks to make decisions</em></li>
</ul>
<p><span id="more-22"></span></p>
<p><em> </em></p></blockquote>
<h1>Fortune-teller</h1>
<p>Most of us enjoy a good circus, carnival, or<br />
county fair. There&#8217;s fun, food, and fortunes. Aah, yes, what would a<br />
fair be without the fortune-teller&#8217;s tent? By the end of this article,<br />
you&#8217;ll know everything you need to spin your fortunes and amaze your<br />
friends with your wisdom.</p>
<p>Before we start the first exercise,<br />
create a new project and add two sprites. The first sprite will be the<br />
seeker. The second sprite will be the teller. Choose any sprites you<br />
want. My seeker will be a clam and my teller will be a snowman. If you<br />
want to add a background, go ahead.</p>
<h2>Time for action &#8211; create a list of questions</h2>
<p>In<br />
order to have a successful fortune-telling, we need two things: a<br />
question and an answer. Let&#8217;s start by defining some questions and<br />
answers:</p>
<ol>
<li>Select the <strong>seeker</strong> from the list of sprites.</li>
<li>From the <strong>Variables</strong> palette, click the <strong>Make a list</strong> button.</li>
<li>In the list name dialog box, type <strong>questions</strong> and select <strong>For this sprite only</strong>.</li>
<li>Click <strong>OK</strong> to create the list. Several new blocks display in the <strong>Variables</strong> palette, and an empty block titled <strong>seeker questions</strong> displays on the stage.<br />
<img src="/games-of-fortune-with-scratch-1.4_files/scratch-article1-image01.png" alt="" width="480" height="314" /></li>
<li>Let&#8217;s think about a couple of questions we may be tempted to ask, such as the following:
<ul>
<li>Will my hair fall out?</li>
<li>How many children will I have?</li>
</ul>
</li>
<li>Let&#8217;s add our proposed questions to the questions list. Click the <strong>plus sign</strong> located in the bottom-left corner of the seeker questions box (on the stage) to display a text input field. Type <strong>Will my hair fall out?</strong></li>
<li>Press the <strong>plus sign</strong> again and enter the second question: <strong>How many children will I have?</strong> We now have two questions in our list.
<p style="margin-left: 40px; margin-right: 40px;"><em>To automatically add the next item in the list, press enter.</em></p>
</li>
<li>Let&#8217;s add a <strong>say for 2 secs</strong> block to the scripts area of the <strong>seeker</strong> sprite so that we can start the dialog.</li>
<li>From the <strong>Variables</strong> palette, drag the <strong>item of questions</strong> block to the input value of the <strong>say for 2 secs</strong> block.</li>
<li>Double-click on the block and the seeker asks, <strong>&#8220;<strong>Will my hair fall out?</strong>&#8220;</strong></li>
<li>Change the value on the item block to last and double-click the block again. This time the seeker asks, <strong>&#8220;<strong>How many children will I have?</strong>&#8220;</strong></li>
</ol>
<p><img src="/games-of-fortune-with-scratch-1.4_files/scratch-article1-image02.png" alt="" width="480" height="282" /></p>
<h3>What just happened?</h3>
<p>I&#8217;m<br />
certain you could come up with a hundred different questions to ask a<br />
fortune-teller. Don&#8217;t worry, you&#8217;ll get your chance to ask more<br />
questions later.</p>
<p>Did you notice that the new list we created<br />
behaved a lot like a variable? We were able to make the questions list<br />
private; we don&#8217;t want our teller to peek at our questions, after all.<br />
Also, the list became visible on the screen allowing us to edit the<br />
contents.</p>
<p>The most notable difference is that we added more than<br />
one item, and each item corresponds to a number. We essentially created<br />
a numbered list.</p>
<p style="margin-left: 40px; margin-right: 40px;"><em>If you work with other programming languages, then you might refer to lists as arrays.</em></p>
<p>Because the seeker&#8217;s questions were contained in a list, we used the <strong>item</strong> block to provide special instructions to the     <strong>say</strong><br />
block in order to ask the question. The first value of the item block<br />
was position, which defaulted to one. The second value was the name of<br />
the list, which defaulted to questions.</p>
<p>In contrast, if we used a variable to store a question, we would only need to supply the name of the variable to the <strong>say</strong> block.</p>
<h3>Have a go hero</h3>
<p>Create an answers list for the <strong>teller</strong> sprite, and add several items to the list. Remember, there are no wrong answers in this exercise.</p>
<h2>Work with an item in a list</h2>
<p>We<br />
can use lists to group related items, but accessing the items in the<br />
list requires an extra level of specificity. We need to know the name<br />
of the list and the position of the item within the list before we can<br />
do anything with the values.</p>
<p>The following table shows the available ways to access a specific item in a list.</p>
<div>
<table class="MsoNormalTable" style="border: medium none ; border-collapse: collapse;" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 10.85pt;">
<td style="border: 1pt solid windowtext; padding: 0in 5.4pt; width: 120.7pt; height: 10.85pt;" width="161" valign="top">
<p class="Pa40"><strong><span style="font-size: 10pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">Position</span></strong><span style="font-size: 10pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;"></span></p>
</td>
<td style="padding: 0in 5.4pt; width: 120.7pt; height: 10.85pt; border: 1pt 1pt 1pt medium solid solid solid none windowtext windowtext windowtext -moz-use-text-color;" width="161" valign="top">
<p class="Pa40"><strong><span style="font-size: 10pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">Description</span></strong><span style="font-size: 10pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;"></span></p>
</td>
<td style="padding: 0in 5.4pt; width: 120.7pt; height: 10.85pt; border: 1pt 1pt 1pt medium solid solid solid none windowtext windowtext windowtext -moz-use-text-color;" width="161" valign="top">
<p class="Pa40"><strong><span style="font-size: 10pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">Uses</span></strong><span style="font-size: 10pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;"></span></p>
</td>
</tr>
<tr style="height: 22.25pt;">
<td style="padding: 0in 5.4pt; width: 120.7pt; height: 22.25pt; border: medium 1pt 1pt none solid solid -moz-use-text-color windowtext windowtext;" width="161" valign="top">
<p class="Pa40"><span style="font-size: 10pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">First</span></p>
</td>
<td style="padding: 0in 5.4pt; width: 120.7pt; height: 22.25pt; border: medium 1pt 1pt medium none solid solid none -moz-use-text-color windowtext windowtext -moz-use-text-color;" width="161" valign="top">
<p class="Pa40"><span style="font-size: 10pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">Identifies the first item in the<br />
list.</span></td>
<td style="padding: 0in 5.4pt; width: 120.7pt; height: 22.25pt; border: medium 1pt 1pt medium none solid solid none -moz-use-text-color windowtext windowtext -moz-use-text-color;" width="161" valign="top">
<p class="Pa40"><span style="font-size: 10pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">Insert, delete, replace, or<br />
retrieve the first item in the list.</span></td>
</tr>
<tr style="height: 22.25pt;">
<td style="padding: 0in 5.4pt; width: 120.7pt; height: 22.25pt; border: medium 1pt 1pt none solid solid -moz-use-text-color windowtext windowtext;" width="161" valign="top">
<p class="Pa40"><span style="font-size: 10pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">Any</span></p>
</td>
<td style="padding: 0in 5.4pt; width: 120.7pt; height: 22.25pt; border: medium 1pt 1pt medium none solid solid none -moz-use-text-color windowtext windowtext -moz-use-text-color;" width="161" valign="top">
<p class="Pa40"><span style="font-size: 10pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">Selects a random item in the list. </span></p>
</td>
<td style="padding: 0in 5.4pt; width: 120.7pt; height: 22.25pt; border: medium 1pt 1pt medium none solid solid none -moz-use-text-color windowtext windowtext -moz-use-text-color;" width="161" valign="top">
<p class="Pa40"><span style="font-size: 10pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">Insert, replace, or retrieve a<br />
random item in the list.</span></td>
</tr>
<tr style="height: 22.25pt;">
<td style="padding: 0in 5.4pt; width: 120.7pt; height: 22.25pt; border: medium 1pt 1pt none solid solid -moz-use-text-color windowtext windowtext;" width="161" valign="top">
<p class="Pa40"><span style="font-size: 10pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">Last</span></p>
</td>
<td style="padding: 0in 5.4pt; width: 120.7pt; height: 22.25pt; border: medium 1pt 1pt medium none solid solid none -moz-use-text-color windowtext windowtext -moz-use-text-color;" width="161" valign="top">
<p class="Pa40"><span style="font-size: 10pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">Selects the last item in the list.</span></p>
</td>
<td style="padding: 0in 5.4pt; width: 120.7pt; height: 22.25pt; border: medium 1pt 1pt medium none solid solid none -moz-use-text-color windowtext windowtext -moz-use-text-color;" width="161" valign="top">
<p class="Pa40"><span style="font-size: 10pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">Insert, delete, replace, or<br />
retrieve the last item in the list.</span></td>
</tr>
<tr style="height: 22.25pt;">
<td style="padding: 0in 5.4pt; width: 120.7pt; height: 22.25pt; border: medium 1pt 1pt none solid solid -moz-use-text-color windowtext windowtext;" width="161" valign="top">
<p class="Pa40"><span style="font-size: 10pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">Variable</span></p>
</td>
<td style="padding: 0in 5.4pt; width: 120.7pt; height: 22.25pt; border: medium 1pt 1pt medium none solid solid none -moz-use-text-color windowtext windowtext -moz-use-text-color;" width="161" valign="top">
<p class="Pa40"><span style="font-size: 10pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">Specifies a variable that contains<br />
a number instead of the default first, any, or last values.</span></td>
<td style="padding: 0in 5.4pt; width: 120.7pt; height: 22.25pt; border: medium 1pt 1pt medium none solid solid none -moz-use-text-color windowtext windowtext -moz-use-text-color;" width="161" valign="top">
<p class="Pa40"><span style="font-size: 10pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">Use the variable to store the<br />
position of an item in the list, then insert, delete, replace, retrieve the<br />
item that corresponds to the value.</span></td>
</tr>
<tr style="height: 22.25pt;">
<td style="padding: 0in 5.4pt; width: 120.7pt; height: 22.25pt; border: medium 1pt 1pt none solid solid -moz-use-text-color windowtext windowtext;" width="161" valign="top">
<p class="Pa40"><span style="font-size: 10pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">Manual input</span></p>
</td>
<td style="padding: 0in 5.4pt; width: 120.7pt; height: 22.25pt; border: medium 1pt 1pt medium none solid solid none -moz-use-text-color windowtext windowtext -moz-use-text-color;" width="161" valign="top">
<p class="Pa40"><span style="font-size: 10pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">Enters a specific item number.</span></p>
</td>
<td style="padding: 0in 5.4pt; width: 120.7pt; height: 22.25pt; border: medium 1pt 1pt medium none solid solid none -moz-use-text-color windowtext windowtext -moz-use-text-color;" width="161" valign="top">
<p class="Pa40"><span style="font-size: 10pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">Insert, delete, replace, or<br />
retrieve a constant item number, such as item 5.</span></td>
</tr>
</tbody>
</table>
</div>
<h2>Import a list</h2>
<p>Entering one item at a time via the Scratch<br />
interface is functional, but the small size of the list box can be<br />
difficult to use when we need to add a large number of items.<br />
Fortunately, we can create a text file outside of Scratch and then<br />
import it into our list.</p>
<p>Before you continue with the exercise,<br />
build your own text file with the fortunes you want to use in response<br />
to the seeker&#8217;s questions. Enter one fortune per line in a text editor,<br />
such as <strong>Notepad</strong>.</p>
<p style="text-align: center;"><img style="float:none;" src="/games-of-fortune-with-scratch-1.4_files/scratch-article1-image03.png" alt="" /></p>
<p>You can use any fortunes you want, but I&#8217;m going to use a list of common Magic 8 ball responses that I found on Wikipedia at <a href="http://en.wikipedia.org/wiki/Magic_8_ball" target="_blank">http://en.wikipedia.org/wiki/Magic_8_ball</a>. My list will contain 19 items to start.</p>
<h2>Time for action &#8211; import a list of fortunes</h2>
<p>If you haven&#8217;t already done so, create a new list and name it <strong>answers</strong>.</p>
<ol>
<li>To import the list, right-click on the <strong>answers list</strong> and choose <strong>import&#8230;</strong> Note: This will erase any items you previously added to the answers list.
<p style="text-align: center;"><img style="float:none;" src="/games-of-fortune-with-scratch-1.4_files/scratch-article1-image04.png" alt="" /></p>
</li>
<li>In the <strong>Import List</strong> dialog box, browse to the fortunes file you saved on your computer prior to starting this exercise and import it.</li>
<li>Think of a new fortune that is not yet in your answers list. We are going to add it to the list. I&#8217;ll use &#8220;<strong>No comment</strong>&#8221; as my new fortune.</li>
<li>Now, let&#8217;s add the new fortune to our list. From the <strong>Variables</strong> palette, find the add block. Replace the default value thing with your new fortune. Make sure the answers list is selected.
<p style="text-align: center;"><img style="float:none;" src="/games-of-fortune-with-scratch-1.4_files/scratch-article1-image05.png" alt="" /></p>
</li>
<li>Double-click on the <strong>add</strong> block to add the new item to the end of the answers list.</li>
</ol>
<h3>What just happened?</h3>
<p>I<br />
don&#8217;t know about you, but I had a much easier time typing in a text<br />
editor than I did typing in the list monitor. Actually, if you took my<br />
lead, you copied the Magic 8 ball responses from Wikipedia and pasted<br />
them into a text file. That way, all you had to do was to clean up some<br />
formatting.</p>
<p>We did add a new fortune to the list via the <strong>add</strong> block. The <strong>add</strong><br />
block always places the new value at the end of the list. Now, my list<br />
contains 20 items. As an alternative, we could have updated the<br />
original fortunes text file and then re-imported the list.</p>
<h3>Reasons to import</h3>
<p>It&#8217;s<br />
true that importing a list makes list creation easy. However, we can<br />
use the Import List functionality in other creative ways. For example,<br />
we could create a game that instructs the player to create a unique<br />
list that he or she can import into Scratch. That way, each player can<br />
customize the game.</p>
<p>If we create a math game, we could ask the player for a varied set of numbers to make the problems different. You get the idea.</p>
<h3>Export a list</h3>
<p>Sometimes,<br />
we may want to export a list from Scratch to a file. For example, as<br />
people play a game, we may want to collect all the scores into a<br />
separate list that we can later export to a text file on our computer.</p>
<p>As<br />
we create our projects, the contents of a list may change from the<br />
original list we imported. In that case, we may want to export the new<br />
list.</p>
<p>To export a list, right-click on the <strong>list monitor</strong> and click <strong>export</strong>. The file automatically saves to the root installation directory for Scratch. In Windows, that is <em>C:Program FilesScratch</em>.</p>
<h4>Pop quiz</h4>
<ol>
<li>If you wanted to group ten related items together, you would create a new:
<ul>
<li>Variable</li>
<li>Numbers block</li>
<li>List</li>
<li>Forever loop</li>
</ul>
</li>
<li>If you want to add many items to a list at one time, how would you do it?
<ul>
<li>Type each item one at a time into the <strong>add</strong> block</li>
<li>Type each item into the list monitor that displays on the stage</li>
<li>Export the list from Scratch</li>
<li>Create a list in a text file and import it via Scratch</li>
</ul>
</li>
</ol>
<h2>Your fortune is …</h2>
<p>Take<br />
a moment to add more questions to the seeker sprite&#8217;s question list.<br />
Now that we have a list of several questions for our seeker to ask and<br />
a list of fortunes for our teller to answer, let&#8217;s create the script<br />
that randomly selects a question.</p>
<h2>Time for action &#8211; tell me a fortune</h2>
<p>Before we begin, hide the lists from the stage by right-clicking on each list and selecting <strong>hide</strong> so that they are out of the way. Let&#8217;s start with the <strong>seeker</strong> sprite. We should have a <strong>say</strong> block in the scripts area from our earlier exercise:</p>
<ol>
<li>We need a way to control our seeker. From the <strong>Control</strong> palette, drag the <strong>when space key pressed</strong> block and attach it to the <strong>say</strong> block.</li>
<li>From<br />
the position drop-down list in the item block, select any. Press the<br />
space key to ask a question. Each time you press the space key, a<br />
random question from the list displays.</li>
<li>We need to let the teller know we&#8217;ve asked a question, and that we expect an answer. From the <strong>Control</strong> palette, add the <strong>broadcast</strong> block.</li>
<li>Add a new broadcast message titled <strong>fortune</strong>.<br />
<img src="/games-of-fortune-with-scratch-1.4_files/scratch-article1-image06.png" alt="" width="480" height="284" /></li>
<li>Every question deserves an answer. Select the <strong>teller</strong> sprite so that we can create the script to provide an answer.</li>
<li>From the <strong>Control</strong> palette, drag the <strong>when I receive</strong> block into the scripts area, and make sure fortune displays as the message value.</li>
<li>From the <strong>Looks</strong> palette, add the <strong>say for 2 secs</strong> block to the <strong>when I receive</strong> block.</li>
<li>Let&#8217;s pick a random item from the answers list. From the <strong>Variables</strong> palette, add the <strong>item</strong> block as the input to the <strong>say</strong> block.</li>
<li>For the <strong>seeker</strong><br />
sprite, we pick a random question using the any position of the item<br />
block. This time, we&#8217;re going to take a slightly different approach to<br />
build a more flexible, but slightly more complicated script. From the <strong>Numbers</strong> palette, add the <strong>pick random</strong> block as the position value of the <strong>item</strong> block.</li>
<li>From the <strong>Variables</strong> palette, add the <strong>length of block</strong> to the second value of the <strong>pick random</strong><br />
block. Make sure the answers list is selected for the value in the<br />
length of block. The following screenshot shows the script for the<br />
teller sprite:<br />
<img src="/games-of-fortune-with-scratch-1.4_files/scratch-article1-image07.png" alt="" width="400" height="87" /></li>
<li>Press the Space bar to make the seeker ask a question. The teller will respond with a fortune.</li>
</ol>
<p style="margin-left: 40px; margin-right: 40px;"><em>Every<br />
item in a list is represented by a number, and when we want to<br />
manipulate a certain value in the list, it&#8217;s the number we refer to.<br />
The list length block gives us a way to always know how many items are<br />
in a list. In our example, our list of answers contains 20 items.</em></p>
<p><img src="/games-of-fortune-with-scratch-1.4_files/scratch-article1-image08.png" alt="" width="480" height="279" /></p>
<h3>What just happened?</h3>
<p>You<br />
are now prepared for a life in the carnival. Based on our script, we<br />
can answer any question that may come our way, and our response will<br />
seem profound. At least that&#8217;s what we&#8217;ll choose to believe.</p>
<p>Our<br />
seeker asked a question, and our teller doled out a random fortune<br />
using items from their respective lists. The script we used for the<br />
teller sprite was decidedly more complex than the script for the seeker<br />
sprite.</p>
<p>In the seeker&#8217;s script, we used the default any value to<br />
select a random item from the list. For the teller, we replaced the any<br />
value with a pick random block. The length of questions block gave the<br />
pick random block the maximum number of items to choose from. In my<br />
example, the script selected a number between 1 and 20 because my<br />
questions list contained 20 items.</p>
<p>You&#8217;re probably asking<br />
yourself why we would write the more complex code when we can achieve<br />
the same result with less. If you are asking that question, good for<br />
you.</p>
<p>The answer, naturally, depends on what we want to<br />
accomplish. If we only want to select a random item from our list, then<br />
the simple script for the seeker suffices. However, let&#8217;s say we want<br />
to instruct our teller to answer every fifth question with a positive<br />
response, and all other questions get a random response.</p>
<p>Let&#8217;s see how we can modify the teller&#8217;s script to guarantee a positive fortune for every fifth question.</p>
<hr size="1" noshade="noshade" />
<div class="header">Scratch 1.4: Beginner&#8217;s Guide</div>
<div style="line-height: 0.4em;"></div>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td width="99" valign="top"><a onclick="javascript: pageTracker._trackPageview('/outgoing/packtpub.com');" href="http://www.packtpub.com/scratch-1-4-beginners-guide/mid/280709dmggns?utm_source=scratchguide.com&amp;utm_medium=affiliate&amp;utm_content=blog&amp;utm_campaign=mdb_000050"><img class="left" title="Scratch 1.4: Beginner’s Guide" src="getting-started-with-scratch-1.4-part1_files/1847196764.png" border="0" alt="Scratch 1.4: Beginner’s Guide" width="99" height="123" /></a></td>
<td valign="top">
<ul>
<li>Learn to program while creating interactive stories, games, and multimedia projects using Scratch</li>
<li>Create interactive stories, games, and multimedia projects that you can reuse in your own classroom</li>
<li>Learn computer programming basics &#8211; no computer science degree required</li>
<li>Connect with the Scratch community for inspiration, advice, and collaboration</li>
<li>Provides hands-on projects that help you learn by experiment and play</li>
</ul>
<p><a onclick="javascript: pageTracker._trackPageview('/outgoing/packtpub.com');" href="http://www.packtpub.com/scratch-1-4-beginners-guide/mid/280709dmggns?utm_source=scratchguide.com&amp;utm_medium=affiliate&amp;utm_content=blog&amp;utm_campaign=mdb_000050">http://www.packtpub.com/scratch-1-3-beginners-guide/book</a></td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" />
<h2>Time for action &#8211; force a positive fortune</h2>
<p>Before we begin<br />
this exercise, re-order your answers list so that all the positive<br />
responses are at the end. Edit the list items in your text editor and<br />
then re-import the list. Make a note of where the first positive<br />
response begins:</p>
<ol>
<li>Our first task is to set up a variable to<br />
count how many questions the seeker asks so that we can calculate<br />
whether or not it&#8217;s time to answer positively. Select the <strong>stage</strong> from the sprites list and create a new variable named <strong>question_number</strong>.</li>
<li>Add the <strong>when flag clicked</strong> block to the scripts area.</li>
<li>From the <strong>Variables</strong> palette, add the <strong>set question_number to 0</strong> block to the <strong>when flag clicked</strong> block. Now, we have a way to reset our calculation.
<p style="text-align: center;"><img style="float:none;" src="/games-of-fortune-with-scratch-1.4_files/scratch-article1-image09.png" alt="" /></p>
</li>
<li>Next, we need to assign the <strong>question_number</strong> variable a value when the seeker asks a question. Click on the <strong>seeker</strong> sprite to display the scripts area</li>
<li>From the Variables palette, snap the <strong>change question_number by 1</strong> block <strong>in place</strong> between the <strong>when space key pressed</strong> and the <strong>say</strong> blocks.
<p style="text-align: center;"><img style="float:none;" src="/games-of-fortune-with-scratch-1.4_files/scratch-article1-image10.png" alt="" /></p>
</li>
<li>Next, make the <strong>teller</strong> sprite give a specific range of answers based on the question. Select the teller sprite to display the scripts area.</li>
<li>From the <strong>Control</strong> palette, add the <strong>if/else</strong> block to the <strong>when I receive</strong> block. Snap the current say block in place after the <strong>if</strong> block.</li>
<li>Change the first input value on the <strong>pick random</strong> block to reflect the item number that begins your positive responses. In my example, that value is 11.</li>
<li>Now, we need to supply a condition to the <strong>if</strong> statement to test whether or not we should issue a positive response. From the <strong>Numbers</strong> palette, add the = block to the <strong>if</strong> block.</li>
<li>Drag the <strong>mod</strong> block into the value to the left of the = sign. Change the value to the right of the equals sign to <strong>0</strong>.</li>
<li>We&#8217;re going to use the mod block to divide <strong>question_number</strong> by 5 so that we can calculate the remainder. Add the <strong>question_number</strong> block to the first value of the <strong>mod</strong> block.</li>
<li>Change the second value of the mod block to 5 so that the block reads <strong>question_number mod 5</strong>.</li>
<li>Test<br />
your script by pressing the Space bar. With our current setup, the<br />
teller responds only on the fifth question, and it&#8217;s always a positive<br />
response.</p>
<p style="text-align: center;"><img style="float:none;" src="/games-of-fortune-with-scratch-1.4_files/scratch-article1-image11.png" alt="" /></p>
</li>
</ol>
<p style="margin-left: 40px; margin-right: 40px;"><em>If<br />
you double-click on the variable monitor block on the stage, a slider<br />
will display. Use the slider to assign a number to the variable before<br />
you run the script as a way to test.<br />
</em></p>
<div style="text-align: center;"><em><img style="float:none;" src="/games-of-fortune-with-scratch-1.4_files/scratch-article1-image12.png" alt="" /></em></div>
<h3>What just happened?</h3>
<p>We asked our teller to issue only a positive response every fifth question, but we needed a way to let our <strong>teller</strong> sprite determine when the fifth question was asked. We set up the <strong>question_number</strong> variable as a way to count the question, and the seeker script updated the value of the <strong>question_number</strong> variable each time we pressed the space key. We call that a counter variable.</p>
<p>The <strong>mod</strong> block gave us the logic we needed to let the teller calculate whether or not to issue a positive response. The <strong>mod</strong> block divided the first number (<strong>question_number</strong>) by the second(5) and returned the remainder.</p>
<p>The <strong>teller</strong> sprite used the <strong>if</strong><br />
block to compare the remainder to zero. We chose zero because when<br />
question_number is a multiple of 5, the remainder was zero. When the<br />
remainder was zero, we executed the code in the <strong>if</strong> block; otherwise, the code in the <strong>else</strong> block ran.</p>
<p>Let&#8217;s evaluate some mod calculations using a divisor of 5:</p>
<ul>
<li>25 mod 5 is 0</li>
<li>32 mod 5 is 2</li>
<li>67 mod 5 is 3</li>
</ul>
<p>In our script, question 25 guarantees a positive response, while questions 32 and 67 do not.</p>
<h3>Counters</h3>
<p>When<br />
we need to know how many items we&#8217;ve processed like we did in our<br />
&#8220;force a positive fortune&#8221; exercise, we use a counter variable. A<br />
counter variable is just an arbitrary name I chose so that we can<br />
easily associate that we are using a variable to count the steps in<br />
some process.</p>
<p>For example, iterating through each item in a list<br />
is a common example of using a variable to count the current list<br />
item&#8217;s position. Consider the block of code in the following screenshot:</p>
<p style="text-align: center;"><img style="float:none;" src="/games-of-fortune-with-scratch-1.4_files/scratch-article1-image13.png" alt="" /></p>
<p>The<br />
sample code in the screenshot uses the counter variable in several<br />
ways. It sets the value to 1 prior to checking the condition in the <strong>forever if</strong><br />
block. It uses the number assigned to counter to determine if we&#8217;ve<br />
processed all the items in the list. If counter is less than the number<br />
of items in the list, the block runs. At the end of the block, we<br />
increment counter&#8217;s value by 1, and the <strong>forever if</strong> block checks the new value of counter</p>
<h3>Keep track of intervals with mod</h3>
<p>If<br />
we identify an interval, then we can create a pattern of events based<br />
on the interval. We already saw an example where we look for the fifth<br />
occurrence of an event, but what if we wanted to make our sprite dance<br />
after 100 seconds elapse? A mod calculation helps us identify the<br />
interval. Assuming our timer starts at zero, the expression<br />
&#8220;current_time mod 100 is 0&#8243; becomes a check to identify every 100th<br />
second.</p>
<p>In our project example, we used the mod block to select<br />
certain items from our list, but we could program any number of events<br />
based on our interval, such as select items from a totally different<br />
list, change backgrounds or costumes, or we could use the mod<br />
calculation to do nothing at all.</p>
<h3>Have a go hero</h3>
<p>Give mod a try. Make the <strong>seeker</strong><br />
sprite do something on every fifth response. Examples of things you<br />
might try include issuing a response to the teller, applying a<br />
graphical transformation, or jumping for joy.</p>
<h3>If/else</h3>
<p>The <strong>forever</strong>, <strong>forever if</strong>, and <strong>if</strong> concepts checks a condition and then runs if the condition is met. We don&#8217;t define what happens when the condition is not met.</p>
<p>In contrast, the <strong>if/else</strong> control block evaluates a condition, and if the evaluation is true, the code in the if block executes. If the <strong>if</strong> condition evaluates to false, then the code in the <strong>else</strong> block executes.</p>
<p>Think<br />
of the ultimatums you give your children, or your parents gave you. If<br />
you clean your room, you get ice cream. Or else, you go to bed without<br />
a snack.</p>
<h3>Pop quiz</h3>
<ol>
<li>The mod block:
<ul>
<li>Modifies a number in the list</li>
<li>Creates a variable that tracks an interval</li>
<li>Transforms the sprite into a leprechaun</li>
<li>Divides two numbers and returns the remainder</li>
</ul>
</li>
<li>We use a counter variable to:
<ul>
<li>Track how many times an event occurs</li>
<li>Identify how many sprites we have in the project</li>
<li>Select a random item from a list</li>
<li>Add a new item to a specific position in the list</li>
</ul>
</li>
</ol>
<h2>Repeat the fortune</h2>
<p>Up<br />
to this point, we&#8217;ve only stored numeric values in our variables, but<br />
variables can store text too. Let&#8217;s add a script to our <strong>teller</strong> sprite to repeat the question.</p>
<h2>Time for action &#8211; my fortune is what?</h2>
<p>What<br />
if we get distracted and miss our fortune? That would be tragic, so<br />
let&#8217;s add some code to the teller sprite that repeats the last fortune<br />
told:</p>
<ol>
<li>Create a private variable for the teller sprite named <strong>your_fortune</strong>. We&#8217;ll use this variable to keep track of the fortune.</li>
<li>We&#8217;ll start with the blocks inside the <strong>if</strong> statement. From the <strong>Variables</strong> palette, snap the set to block in place between the <strong>if</strong> block and the <strong>say</strong> block. Select your_fortune as the variable so that the block reads set <strong>your_fortune to 0</strong>.</li>
<li>We need to replace the <strong>0</strong> value in the <strong>set to</strong> block with the code that selects a random item from the answers list. Remember, we&#8217;re working with the <strong>if</strong> block right now. Click on the <strong>item</strong> block and drag the entire block into the to value of the set to block.</li>
<li>From the <strong>Variables</strong> palette, drag the <strong>your_fortune</strong> block into the value of the <strong>say</strong> block. Refer to the following screenshot for the new script:
<p style="text-align: center;"><img style="float:none;" src="/games-of-fortune-with-scratch-1.4_files/scratch-article1-image14.png" alt="" width="540px" /></p>
</li>
<li>Apply the same changes to the else block. Refer to the following screenshot for help:
<p style="text-align: center;"><img style="float:none;" src="/games-of-fortune-with-scratch-1.4_files/scratch-article1-image15.png" alt="" width="540px" /></p>
</li>
<li>Get a fortune by pressing the Space bar. Notice that the your_fortune monitor reports the teller&#8217;s fortune.
<p style="text-align: center;"><img src="/games-of-fortune-with-scratch-1.4_files/scratch-article1-image16.png" alt="" /></p>
</li>
<li>Now, we need a way to prompt the teller to repeat the message. We&#8217;ll add a <strong>when clicked</strong> control block to the <strong>teller</strong> sprite. From the <strong>Control</strong> palette, add the <strong>when teller clicked</strong> block to the scripts area.</li>
<li>From the Looks palette, add the <strong>say for 2 secs</strong> block to the <strong>when teller clicked</strong> block.</li>
<li>From the Variables palette, add the <strong>your_fortune</strong> block as the message value for the <strong>say</strong> block.</li>
<li>Click the teller sprite to repeat the last fortune.</li>
</ol>
<p style="text-align: center;"><img style="float:none;" src="/games-of-fortune-with-scratch-1.4_files/scratch-article1-image17.png" alt="" width="540px" /></p>
<h3>What just happened?</h3>
<p>Like thoughts, fortunes can be fleeting. That&#8217;s why we captured our fortune in the <strong>your_fortune</strong><br />
variable. We replaced where in our script we selected the fortune. Our<br />
logic to pick a random item from the answers list became the input to<br />
the set to block. And for the say block, we replaced the message value<br />
with the <strong>your_fortune</strong> variable.</p>
<p>Now, if we get a fortune we like, we can make the teller repeat it over and over.</p>
<h3>Holding text in a variable</h3>
<p>We<br />
can type text directly into the say block. This means that if we want<br />
to change what the sprite says, we have to find the say block in the<br />
script and change the message.</p>
<p>When we work with dynamic data, we<br />
sometimes want to capture that data so that we can use it later. We<br />
already learned how we can use variables to store numeric data, but<br />
having the ability to store text adds a whole new level of<br />
functionality to our projects, such as simulating dynamic conversations.</p>
<p style="margin-left: 40px; margin-right: 40px;"><em>Other programming languages often refer to a text phrase as a <span style="font-weight: bold;">string</span>.</em></p>
<p>Variables<br />
are one of the most important programming concepts we can use. A<br />
majority of the projects you create will need a variable, especially as<br />
the projects become more interactive and complex.</p>
<h3>Text entry limitations</h3>
<p>Now,<br />
it is a logical time for us to build a way that prompts the user to<br />
type a question for the teller. However, the current version of Scratch<br />
(1.3) doesn&#8217;t allow us to prompt the user for text input that we can<br />
use in our scripts.</p>
<h3>Next steps</h3>
<p>Our focus has been on<br />
using lists and variables to drive the action in our game. If you<br />
wanted to expand on this game, try adding graphical effects to the<br />
sprites and creating a background to begin to tell a story.</p>
<p>Using<br />
the concepts in this article, you could create other games of chance,<br />
such as blackjack, bingo, or a lottery number predictor.</p>
<h1>Summary</h1>
<p>We<br />
have seen the power that lists and variables give us to create dynamic,<br />
flexible, and fun projects. We learned how to manipulate lists, a<br />
special kind of variable, to collect a group of related items. We<br />
continued to explore variables by using them to store text. The mod<br />
block helped us identify intervals as we iterated through our list. We<br />
used a variable to keep track of the interval so that we could program<br />
specific events based on when an interval occurred.</p>
<hr size="1" noshade="noshade" />
<div class="header">Scratch 1.4: Beginner&#8217;s Guide</div>
<div style="line-height: 0.4em;"></div>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td width="99" valign="top"><a onclick="javascript: pageTracker._trackPageview('/outgoing/packtpub.com');" href="http://www.packtpub.com/scratch-1-4-beginners-guide/mid/280709dmggns?utm_source=scratchguide.com&amp;utm_medium=affiliate&amp;utm_content=blog&amp;utm_campaign=mdb_000050"><img class="left" title="Scratch 1.4: Beginner’s Guide" src="/getting-started-with-scratch-1.4-part1_files/1847196764.png" border="0" alt="Scratch 1.4: Beginner’s Guide" width="99" height="123" /></a></td>
<td valign="top">
<ul>
<li>Learn to program while creating interactive stories, games, and multimedia projects using Scratch</li>
<li>Create interactive stories, games, and multimedia projects that you can reuse in your own classroom</li>
<li>Learn computer programming basics &#8211; no computer science degree required</li>
<li>Connect with the Scratch community for inspiration, advice, and collaboration</li>
<li>Provides hands-on projects that help you learn by experiment and play</li>
</ul>
<p><a onclick="javascript: pageTracker._trackPageview('/outgoing/packtpub.com');" href="http://www.packtpub.com/scratch-1-4-beginners-guide/mid/280709dmggns?utm_source=scratchguide.com&amp;utm_medium=affiliate&amp;utm_content=blog&amp;utm_campaign=mdb_000050">http://www.packtpub.com/scratch-1-3-beginners-guide/book</a></td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" />
]]></content:encoded>
			<wfw:commentRss>http://www.scratchguide.com/scratch-tutorial-lists-mod-if-else/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Scratch Programming &#8211; Sprites, Broadcasts, Community</title>
		<link>http://www.scratchguide.com/scratch-programming-sprites-broadcasts-community/</link>
		<comments>http://www.scratchguide.com/scratch-programming-sprites-broadcasts-community/#comments</comments>
		<pubDate>Thu, 05 Nov 2009 04:36:42 +0000</pubDate>
		<dc:creator>Michael Badger</dc:creator>
				<category><![CDATA[Scratch Tutorial]]></category>
		<category><![CDATA[broadcast]]></category>
		<category><![CDATA[costumes]]></category>
		<category><![CDATA[paint editor]]></category>
		<category><![CDATA[sample chapter]]></category>
		<category><![CDATA[sprites]]></category>

		<guid isPermaLink="false">http://scratchguide.com/book/?p=19</guid>
		<description><![CDATA[This scratch tutorial is the second half of chapter 3 from the book, Scratch 1.4: Beginner&#8217;s Guide. If you need a more advanced topic, check out my tutorial Scratch Programming Tutorial #3. Enjoy!
Each Scratch project contains sprites with costumes, scripts,
blocks, and a stage with backgrounds. In the first part, we built a couple of sample [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.scratchguide.com%2Fscratch-programming-sprites-broadcasts-community%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.scratchguide.com%2Fscratch-programming-sprites-broadcasts-community%2F" height="61" width="51" /></a></div><p>This scratch tutorial is the second half of chapter 3 from the book, <em>Scratch 1.4: Beginner&#8217;s Guide</em>. If you need a more advanced topic, check out my tutorial <a title="Scratch Programming Tutorial" href="/index.php?page=scratch-programming-tutorial-3">Scratch Programming Tutorial #3</a>. Enjoy!</p>
<blockquote><p><em>Each Scratch project contains sprites with costumes, scripts,<br />
blocks, and a stage with backgrounds. In the first part, we built a couple of sample scripts to demonstrate how we can control the sprites in a project. For example, we used <strong>motion</strong> to move the sprites and forever loops to keep the sprite moving.</em></p>
<p><em>In this part of the article, we will use broadcast messages to coordinate the actions of multiple sprites. We will conclude this article by sampling and remixing projects from Scratch&#8217;s sample projects and from the Scratch web site.</em></p></blockquote>
<p><span id="more-19"></span></p>
<h2>Add sprites to the stage</h2>
<p>In the first part we learned that if we want something done in Scratch, we tell a sprite by using blocks in the scripts area. A single sprite can&#8217;t be responsible for carrying out all our actions, which means we&#8217;ll often need to add sprites to<br />
accomplish our goals.</p>
<p>We can add sprites to the stage in one of the following four ways: <strong>paint new sprite, choose new sprite from file, get a surprise sprite</strong>, or by <strong>duplicating a sprite</strong>. Duplicating a sprite is not in the scope of this article. The buttons to insert a new sprite using the other three methods are directly above the sprites list.</p>
<p>Let&#8217;s be surprised. Click on get surprise sprite (the button with the &#8220;?&#8221; on it.). If the second sprite covers up the first sprite, grab one of them with your mouse and drag it around the screen to reposition it.</p>
<p style="text-align: center;"><img style="float:none;" src="/getting-started-with-scratch-1.4-part2_files/scratch-article3-image01.png" alt="" /></p>
<p>If you don&#8217;t like the sprite that popped up, delete it by selecting the scissors from the tool bar and clicking on the sprite. Then click on <strong>get surprise sprite</strong> again.</p>
<p>Each sprite has a name that displays beneath the icon. See the previous screenshot for an example. Right now, our sprites are cleverly named <strong>Sprite1</strong> and <strong>Sprite2</strong>.</p>
<h3>Get new sprites</h3>
<p>The <strong>create new sprite</strong> option allows you to draw a sprite using the Paint Editor when you need a sprite that you can&#8217;t find anywhere else. You can also create sprites using third-party graphics programs, such as Adobe Photoshop, GIMP, and Tux Paint.</p>
<p>If you create a sprite in a different program, then you need to import the sprite using the <strong>choose new sprite from file</strong> option. Scratch also bundles many sprites with the installation, and the <strong>choose new sprite</strong> from <strong>file</strong> option will allow you to select one of the included files.</p>
<p>The bundled sprites are categorized into <strong>Animals, Fantasy, Letters, People, Things</strong>, and <strong>Transportation</strong>, as seen in the following screenshot:</p>
<p style="text-align: center;"><img style="float:none;" src="/getting-started-with-scratch-1.4-part2_files/scratch-article3-image02.png" alt="" /></p>
<p>If you look at the screenshot carefully, you&#8217;ll notice the folder path lists <strong>Costumes</strong>, not sprites. A costume is really a sprite.</p>
<p>If you want to be surprised, then use the <strong>get surprise sprite</strong> option to add a sprite to the project. This option picks a random entry from the gallery of bundled sprites.</p>
<p>We can also add a new sprite by duplicating a sprite that&#8217;s already in the project by right-clicking on the sprite in the sprites list and choosing <strong>duplicate</strong> (command C on Mac). As the name implies, this creates a clone of the sprite.</p>
<p>The method we use to add a new sprite depends on what we are trying to do and what we need for our project.</p>
<h3>Time for action – spin sprite spin</h3>
<ol>
<li>Let&#8217;s get our sprites spinning.</li>
<li>To start, click on <strong>Sprite1</strong> from the sprites list. This will let us edit the script for <strong>Sprite1</strong>.</li>
<li>From the <strong>Motion</strong> palette, drag the <strong>turn clockwise 15 degrees</strong> block into the script for <strong>Sprite1</strong> and snap it in place after the <strong>if on edge, bounce</strong> block.</li>
<li>Change the value on the <strong>turn</strong> block to <strong>5</strong>.
<p style="text-align: center;"><img style="float:none;" src="/getting-started-with-scratch-1.4-part2_files/scratch-article3-image03.png" alt="" /></p>
</li>
<li>From the sprites list, click on <strong>Sprite2</strong>.</li>
<li>From the <strong>Motion</strong> palette, drag the <strong>turn clockwise 15 degrees</strong> block into the scripts area.</li>
<li>Find the <strong>repeat 10</strong> block from the <strong>Control</strong> palette and snap it around the <strong>turn clockwise 15 degrees</strong> block.</li>
<li>Wrap the script in the <strong>forever</strong> block.</li>
<li>Place the <strong>when space key pressed</strong> block on top of the entire stack of blocks.</li>
<li>From the <strong>Looks</strong> palette, snap the <strong>say hello for 2 secs</strong> block onto the bottom of the <strong>repeat</strong> block and above the forever block.</li>
<li>Change the value on the <strong>repeat</strong> block to <strong>100</strong>. Change the value on the <strong>turn clockwise 15 degrees</strong> block to <strong>270</strong>. Change the value on the <strong>say</strong> block to <strong>I&#8217;m getting dizzy!</strong></li>
<li>Press the Space bar and watch the second sprite spin. Click the flag and set the second sprite on a trip around the stage.<br />
<img src="/getting-started-with-scratch-1.4-part2_files/scratch-article3-image04.png" alt="" width="480" height="212" /></li>
</ol>
<h4><em>What just happened?</em></h4>
<p>We have two sprites on the screen acting independently of each other. It seems simple enough, but let&#8217;s step through our script.</p>
<p>Our cat got bored bouncing in a straight line across the stage, so we introduced some rotation. Now as the cat walked, it turned five degrees each time the blocks in the forever loop ran. This caused the cat to walk in an arc. As the cat bounced off the stage, it got a new trajectory.</p>
<p>We told <strong>Sprite2</strong> to turn 270 degrees for 100 consecutive times. Then the sprite stopped for two seconds and displayed a message, &#8220;<strong>I&#8217;m getting dizzy!</strong>&#8221; Because the script was wrapped in a forever block, <strong>Sprite2</strong> started tumbling again.</p>
<p>We used the space bar as the control to set <strong>Sprite2</strong> in motion. However, you noticed that <strong>Sprite1</strong> did not start until we clicked the flag. That&#8217;s because we programmed <strong>Sprite1</strong> to start when the flag was clicked.</p>
<h4>Have a go hero</h4>
<p>Make <strong>Sprite2</strong> less spastic. Instead of turning <strong>270</strong> degrees, try a smaller value, such as <strong>5</strong>.</p>
<h2>Sometimes we need inspiration</h2>
<p>So far, we&#8217;ve had a cursory introduction to Scratch, and we&#8217;ve created a few animations to illustrate some basic concepts. However, now is a good time to pause and talk about inspiration.</p>
<p>Sometimes we learn by examining the work of other people and adapting that work to create something new that leads to creative solutions.</p>
<p>When we want to see what other people are doing with Scratch, we have two places to turn. First, our Scratch installation contains dozens of sample projects. Second, the Scratch web site at <a href="http://scratch.mit.edu/" target="_blank">http://scratch.mit.edu</a> maintains a thriving community of Scratchers.</p>
<h3>Browse Scratch&#8217;s projects</h3>
<p>Scratch includes several categories of projects for <strong>Animation, Games, Greetings, Interactive Art, Lists, Music and Dance, Names, Simulations, Speak up,</strong> and <strong>Stories</strong>.</p>
<h3>Time for action – spinner</h3>
<p>Let&#8217;s dive right in.</p>
<p>From the Scratch interface, click the <strong>Open</strong> button to display the <strong>Open Project</strong> dialog box, as seen in the following screenshot.</p>
<p style="text-align: center;"><img style="float:none;" src="/getting-started-with-scratch-1.4-part2_files/scratch-article3-image05.png" alt="" /></p>
<ol>
<li>Click on the <strong>Examples</strong> button.</li>
<li>Select <strong>Simulations</strong> and click <strong>OK</strong>.</li>
<li>Select <strong>Spinner</strong> and click <strong>OK</strong> to load the Spinner project.</li>
<li>Follow the instructions on the screen and spin the arrow by clicking on the arrow.</li>
<li>We&#8217;re going to edit the spinner wheel. From the sprites list, click on <strong>Stage</strong>. From the scripts area, click the <strong>Backgrounds</strong> tab. Click <strong>Edit</strong> on background number 1 to open the Paint Editor.</li>
<li>Select a unique color from the color palette, such as purple.</li>
<li>Click<br />
on the paint bucket from the toolbar, then click on one of the<br />
triangles in the circle to change its color. The paint bucket is<br />
highlighted in the following screenshot.</li>
<li>Click <strong>OK</strong> to return to our project.</li>
</ol>
<p style="text-align: center;"><img style="float:none;" src="/getting-started-with-scratch-1.4-part2_files/scratch-article3-image06.png" alt="" /></p>
<h4><em>What just happened?</em></h4>
<p>We opened a community project called Spinner that came bundled with Scratch. When we clicked on the arrow, it spun and randomly selected a color from the wheel. We got our first look at a project that uses a background for the stage and modified the background using Scratch&#8217;s built-in image editor.</p>
<p>The Paint Editor in Scratch provides a basic but functional image editing environment. Using the Paint Editor, we can create a new sprite/background and modify a sprite/background. This can be useful if we are working with a sprite or background that someone else has created.</p>
<h4>Costume versus background</h4>
<p>A<br />
costume defines the look of a sprite while a background defines the<br />
look of the stage. A sprite may have multiple costumes just as the<br />
stage can have multiple backgrounds.</p>
<p>When we want to work with the backgrounds on the stage, we use the <strong>switch to background</strong> and <strong>next background</strong> blocks. We use the <strong>switch to costume</strong> and <strong>next costume</strong> blocks when we want to manipulate a sprite&#8217;s costume.</p>
<p>Actually, if you look closely at the available looks blocks when you&#8217;re working with a sprite, you&#8217;ll realize that you can&#8217;t select the backgrounds. Likewise, if you&#8217;re working with the stage, you can&#8217;t select costumes.</p>
<hr size="1" noshade="noshade" />Scratch 1.4: Beginner&#8217;s Guide</p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td width="99" valign="top"><a onclick="javascript: pageTracker._trackPageview('/outgoing/packtpub.com');" href="http://www.packtpub.com/scratch-1-4-beginners-guide/mid/280709dmggns?utm_source=scratchguide.com&amp;utm_medium=affiliate&amp;utm_content=blog&amp;utm_campaign=mdb_000050"><img class="left" title="Scratch 1.4: Beginner’s Guide" src="getting-started-with-scratch-1.4-part1_files/1847196764.png" border="0" alt="Scratch 1.4: Beginner’s Guide" width="99" height="123" /></a></td>
<td valign="top">
<ul>
<li>Learn to program while creating interactive stories, games, and multimedia projects using Scratch</li>
<li>Create interactive stories, games, and multimedia projects that you can reuse in your own classroom</li>
<li>Learn computer programming basics &#8211; no computer science degree required</li>
<li>Connect with the Scratch community for inspiration, advice, and collaboration</li>
<li>Provides hands-on projects that help you learn by experiment and play</li>
</ul>
<p><a onclick="javascript: pageTracker._trackPageview('/outgoing/packtpub.com');" href="http://www.packtpub.com/scratch-1-4-beginners-guide/mid/280709dmggns?utm_source=scratchguide.com&amp;utm_medium=affiliate&amp;utm_content=blog&amp;utm_campaign=mdb_000050">http://www.packtpub.com/scratch-1-3-beginners-guide/book</a></td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" />
<h2>Time for action – broadcast a message</h2>
<p>We&#8217;re going to continue spinning. Let&#8217;s make the color wheel strobe as the arrow spins:</p>
<ol>
<li>We need to duplicate the existing background. Select the <strong>Stage</strong> sprite and click on the <strong>Backgrounds</strong> tab in the script area. Click the <strong>Copy</strong> button to duplicate <strong>background1</strong>.</li>
<li>Now, let&#8217;s flip the second background. For <strong>background2</strong>, click the <strong>Edit</strong> button to open the Paint Editor. Click the <strong>Flip Horizontally</strong> button that is located above the editor window and click <strong>OK</strong> to exit the Paint Editor.
<p style="text-align: center;"><img style="float:none;" src="getting-started-with-scratch-1.4-part2_files/scratch-article3-image07.png" alt="" /></p>
</li>
<li>Select the <strong>Spinner</strong> sprite from the list of sprites.</li>
<li>We&#8217;re going to program the sprite to send a message. From the <strong>Control</strong> palette, add the <strong>broadcast</strong> block to the script before the <strong>turn 5 degrees</strong> block. Click on the message drop-down list of the <strong>broadcast</strong> block and choose <strong>New</strong>.
<p style="text-align: center;"><img src="/getting-started-with-scratch-1.4-part2_files/scratch-article3-image08.png" alt="" /></p>
</li>
<li>Type <strong>spin</strong> in the <strong>message name</strong> dialog box and click <strong>OK</strong>.</li>
<li>We&#8217;re going to tell the stage to listen for the broadcast message. Select <strong>Stage</strong> from the list of sprites.</li>
<li>From the <strong>Control</strong> palette, add the <strong>when I receive</strong> block to the script area. Select <strong>spin</strong> from the message drop-down list.
<p style="text-align: center;"><img style="float:none;" src="/getting-started-with-scratch-1.4-part2_files/scratch-article3-image09.png" alt="" /></p>
</li>
<li>From the <strong>Looks</strong> palette, add the <strong>next background</strong> block to the script.</li>
<li>Click on the arrow.</li>
</ol>
<h4><em>What just happened?</em></h4>
<p>Now we&#8217;re programming in Scratch!</p>
<p>Our first step was to duplicate the existing background so we could flip it horizontally. We could have flipped the background vertically instead. Or, we could have flipped it both horizontally or vertically—it&#8217;s a matter of whimsical choice.</p>
<p>We used a <strong>broadcast</strong> block on the <strong>Spinner</strong> sprite to let the stage know when we clicked the arrow. The arrow sent the message <strong>spin</strong>, which told the stage to switch to the next background, and this produced a strobe effect.</p>
<p>The stage knew how many times to switch backgrounds because when we clicked on the arrow, the script selected a random number between 25 and 200. In the original project, the random number controlled how many times the arrow spun around the circle.</p>
<p>In our new project, if the script selected a random number of 30, the following set of commands repeated 30 times in sequence: broadcast the message <strong>spin</strong> and turn to the right 5 degrees. For each spin, the background switched.</p>
<h4>Broadcast messages coordinate sprites</h4>
<p>When a sprite broadcasts a message, it&#8217;s a clue to the other sprites that something should happen. In order for another sprite to react to the message, it needs to be told to listen for the broadcast message by using a <strong>when I receive</strong> block. Multiple sprites can be controlled with a single broadcast. If a sprite is not instructed to listen for a broadcast message, then it ignores the message.</p>
<p>You can think of broadcasts as a conversation starter. Conversations require two or more participants to engage. If I pass you on the street, I might say, &#8220;Hi, reader.&#8221; Depending on the circumstances you might respond in one of three ways. First, you might say, &#8220;Hi, Mike.&#8221;<br />
Second, you might wave. Third, you might ignore my message and continue on your path.</p>
<h2>Browse the Scratch community</h2>
<p>Learning by doing is a great way to figure things out, but interacting with the code of other Scratch programmers provides an insight and an inspiration that you might not find on your own. If you visit the Scratch web site at <a href="http://scratch.mit.edu/" target="_blank">http://scratch.mit.edu</a>, you can browse community projects by <strong>Newest Projects, Featured Projects, Top Remixed Lately, Surprise Projects, Top Loved Lately, Top Downloaded Lately,</strong> and <strong>Top Viewed Lately</strong>.</p>
<p style="margin-left: 40px; margin-right: 40px;"><em>To view the Scratch projects on a web page, you need a Java Runtime environment installed.</em></p>
<p>Take some time and click through several projects so you get a broad sampling. As you view the work of others, stop thinking like a user and start thinking like a designer and a programmer. When you find something you like, ask yourself, &#8220;How does that work?&#8221; Then try to visualize how you might build the same thing. This exercise gets easier as you gain more experience.</p>
<h3>Time for action – create an account</h3>
<p>In order to download projects to our local computer, we need to create an account.</p>
<ol>
<li>From the Scratch home page, click the <strong>Signup</strong> link to create an account or go to <a href="http://scratch.mit.edu/signup" target="_blank">http://scratch.mit.edu/signup</a>.</li>
<li>Enter all required information in the <strong>Create an account</strong> form.</li>
<li>Click the <strong>sign up</strong> button to create the account.</li>
<li>Read the terms of use at <a href="http://scratch.wik.is/Terms_of_use" target="_blank">http://scratch.wik.is/Terms_of_use</a>. It&#8217;s a link in the page footer.</li>
<li>Welcome to the Scratch community.</li>
</ol>
<h4><em>What just happened?</em></h4>
<p>We created an account at the Scratch web site. We can share our projects, but for now, we need an account so that we can download a project.</p>
<h3>Abide by the terms of use</h3>
<p>It&#8217;s important that we take a few moments to read the terms of use policy so that we know what the community expects from us. Directly from Scratch&#8217;s terms of use, the major points are:</p>
<ul>
<li>Be respectful</li>
<li>Offer constructive comments</li>
<li>Give credit</li>
<li>Help keep the site friendly</li>
</ul>
<h3>Time for action – download a project</h3>
<p>Without further hesitation, find a project you like and download it:</p>
<ol>
<li>Click the link to download the project.</li>
<li>When prompted by your web browser, save the project to your computer.</li>
<li>Next, open the project in Scratch. From the Scratch interface, click on the <strong>Open</strong> button.</li>
<li>In the <strong>Open Project</strong> dialog box, navigate your filesystem and open the project you just downloaded.</li>
</ol>
<h4><em>What just happened?</em></h4>
<p>We found a project we liked, we downloaded it, and then we opened it. As you review the project code in the Scratch interface, you can begin to answer the question, &#8220;How does it work?&#8221; You did remember to think like a designer and not a user, right?</p>
<p>Now that you saw the code, are you surprised by what you saw? Don&#8217;t worry about whether or not you understand what it all means. You will.</p>
<p>Our mothers taught us to share, which brings us to the other implicit concept in this exercise. The Scratch community also encourages us to share, and each project on<br />
the Scratch web site is available under a <strong>Creative Commons Attribution-Share Alike License</strong>.</p>
<h3>Creative Commons</h3>
<p>The Attribution-Share Alike license is simple in concept and practice. When you find an interesting project, feel free to download it and remix it to create something new. Then credit the original author. The project notes make a great place to credit the work of others. We can make several projects to share with the Scratch community, and hope that our work inspires someone else to create something new and unexpected.</p>
<p>For more information about Creative Commons licensing, visit <a href="http://www.creativecommons.org/" target="_blank">www.creativecommons.org</a>.</p>
<h4>Have a go hero</h4>
<p>Modify the project you just created in some way. If you&#8217;re not sure where to begin, try inputting different values into the blocks to see what happens.</p>
<p>There is no right way, just exploration.</p>
<h2>Summary</h2>
<p>This two-part article helped us feel comfortable working with Scratch by covering some basic concepts. Each Scratch project contains spriteswith costumes, scripts, blocks, and a stage with backgrounds.</p>
<p>In this article, we built a couple of sample scripts to demonstrate how we can control the sprites in a project. For example, we used motion to move the sprites, forever loops to keep the sprite moving, and broadcast messages to coordinate the actions of multiple sprites.</p>
<p>We finished the article by sampling and remixing projects from Scratch&#8217;s sample projects and from the Scratch web site. We also discovered that Scratch promotes sharing as a way to learn and encourage ideas.</p>
<hr size="1" noshade="noshade" />Scratch 1.4: Beginner&#8217;s Guide</p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td width="99" valign="top"><a onclick="javascript: pageTracker._trackPageview('/outgoing/packtpub.com');" href="http://www.packtpub.com/scratch-1-4-beginners-guide/mid/280709dmggns?utm_source=scratchguide.com&amp;utm_medium=affiliate&amp;utm_content=blog&amp;utm_campaign=mdb_000050"><img class="left" title="Scratch 1.4: Beginner’s Guide" src="/getting-started-with-scratch-1.4-part1_files/1847196764.png" border="0" alt="Scratch 1.4: Beginner’s Guide" width="99" height="123" /></a></td>
<td valign="top">
<ul>
<li>Learn to program while creating interactive stories, games, and multimedia projects using Scratch</li>
<li>Create interactive stories, games, and multimedia projects that you can reuse in your own classroom</li>
<li>Learn computer programming basics &#8211; no computer science degree required</li>
<li>Connect with the Scratch community for inspiration, advice, and collaboration</li>
<li>Provides hands-on projects that help you learn by experiment and play</li>
</ul>
<p><a onclick="javascript: pageTracker._trackPageview('/outgoing/packtpub.com');" href="http://www.packtpub.com/scratch-1-4-beginners-guide/mid/280709dmggns?utm_source=scratchguide.com&amp;utm_medium=affiliate&amp;utm_content=blog&amp;utm_campaign=mdb_000050">http://www.packtpub.com/scratch-1-3-beginners-guide/book</a></td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" />
]]></content:encoded>
			<wfw:commentRss>http://www.scratchguide.com/scratch-programming-sprites-broadcasts-community/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Scratch Programming Introduction &#8211; The Basics</title>
		<link>http://www.scratchguide.com/scratch-programming-introduction-the-basics/</link>
		<comments>http://www.scratchguide.com/scratch-programming-introduction-the-basics/#comments</comments>
		<pubDate>Thu, 05 Nov 2009 03:49:13 +0000</pubDate>
		<dc:creator>Michael Badger</dc:creator>
				<category><![CDATA[Scratch Tutorial]]></category>
		<category><![CDATA[costumes]]></category>
		<category><![CDATA[motion]]></category>
		<category><![CDATA[sample chapter]]></category>
		<category><![CDATA[sprites]]></category>

		<guid isPermaLink="false">http://scratchguide.com/book/?p=14</guid>
		<description><![CDATA[This Scratch tutorial is the first half of chapter 3 from the book, Scratch 1.4: Beginner&#8217;s Guide. The tutorial introduces Scratch programming and the Scratch interface. 
The anticipation of learning a new programming
language can sometimes leave us frozen on the starting line, not
knowing what to expect or where to start. In this two-part article, we [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.scratchguide.com%2Fscratch-programming-introduction-the-basics%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.scratchguide.com%2Fscratch-programming-introduction-the-basics%2F" height="61" width="51" /></a></div><p>This Scratch tutorial is the first half of chapter 3 from the book, <em>Scratch 1.4: Beginner&#8217;s Guide</em>. The tutorial introduces Scratch programming and the Scratch interface. </p>
<p><em>The anticipation of learning a new programming<br />
language can sometimes leave us frozen on the starting line, not<br />
knowing what to expect or where to start. In this two-part article, we will:</em></p>
<ul>
<li>Take a tour of the Scratch interface</li>
<li>Create a couple of sample projects</li>
<li>Learn some basic Scratch programming concepts</li>
<li>Get our minds racing</li>
</ul>
<p>Our specific objectives include:</p>
<ul>
<li>Learning how to work with Scratch</li>
<li>Learning basic Scratch programming commands</li>
<li>Finding inspiration to fuel our creativity</li>
</ul>
<p><span id="more-14"></span>
</p></blockquote>
<p>Before we create any code, let&#8217;s make sure we speak the same language.</p>
<h2>The interface at a glance</h2>
<p>When we encounter software that&#8217;s unfamiliar to us, we often wonder, &#8220;Where do I begin?&#8221; Together, we&#8217;ll answer that question and click through some important sections of the Scratch interface so that we can quickly start creating our own projects.</p>
<p>Now, open Scratch and let&#8217;s begin.</p>
<h3>Time for action &#8211; first step</h3>
<p>When we open Scratch, we notice that the development environment roughly divides into three distinct sections, as seen in the following screenshot. Moving from left to right, we have the following sections in sequential order:</p>
<ul>
<li>Blocks palette</li>
<li>Script editor</li>
<li>Stage</li>
</ul>
<p><img src="/getting-started-with-scratch-1.4-part1_files/scratch-article2-image01.png" alt="" width="432" height="323" /></p>
<p>Let&#8217;s see if we can get our cat moving:</p>
<ol>
<li>In the blocks palette, click on the <strong>Looks</strong> button.</li>
<li>Drag the <strong>switch to costume</strong> block onto the scripts area.</li>
<li>Now, in the blocks palette, click on the <strong>Control</strong> button.</li>
<li>Drag the <strong>when flag clicked</strong> block to the scripts area and snap it on top of the <strong>switch to costume</strong> block, as illustrated in the following screenshot.
<p style="margin-left: 40px; margin-right: 40px;"><em><strong>How to snap two blocks together?</strong></em></p>
<p><em> </em><em>As you drag a block onto another block, a white line displays to indicate that the block you are dragging can be added to the script. When you see the white line, release your mouse to snap the block in place.</em></p>
<p style="text-align: center;"><img style="float:none;" src="/getting-started-with-scratch-1.4-part1_files/scratch-article2-image02.png" alt="" /></p>
</li>
<li>In the scripts area, click on the <strong>Costumes</strong> tab to display the sprite&#8217;s costumes.
<p style="text-align: center;"><img style="float:none;" src="/getting-started-with-scratch-1.4-part1_files/scratch-article2-image03.png" alt="" /></p>
</li>
<li>Click on <strong>costume2</strong> to change the sprite on the stage. Now, click back on <strong>costume1</strong> to change how the sprite displays on the stage.</li>
<li>Directly beneath the stage is a sprites list. The current list displays <strong>Sprite1</strong> and <strong>Stage</strong>.</li>
<li>Click on the sprite named <strong>Stage</strong> and notice that the scripts area changes. Click back on <strong>Sprite1</strong> in the sprites list and again note the change to the scripts area.</li>
<li>Click on the flag above the stage to set our first Scratch program in motion. Watch closely, or you might miss it.<br />
<img src="/getting-started-with-scratch-1.4-part1_files/scratch-article2-image04.png" alt="" width="480" height="264" /></li>
</ol>
<h4><em>What just happened?</em></h4>
<p>Congratulations! You created your first Scratch project. Let&#8217;s take a closer look at what we did just now.</p>
<p>As we clicked through the blocks palette, we saw that the available blocks changed depending on whether we chose <strong>Motion</strong>, <strong>Looks</strong>, or <strong>Control</strong>. Each set of blocks is color-coded to help us easily identify them in our scripts.</p>
<p>The first block we added to the script instructed the sprite to display <strong>costume2</strong>. The second block provided a way to control our script by clicking on the flag.</p>
<p style="text-align: center;"><img style="float:none;" src="/getting-started-with-scratch-1.4-part1_files/scratch-article2-image05.png" alt="" /></p>
<p>Did you look closely at the blocks as you snapped the control block into the looks block? The bottom of the <strong>when flag clicked</strong> block had a protrusion like a puzzle piece that fits the indent on the top of the <strong>switch to costume</strong> block.</p>
<p>As children, most of us probably have played a game where we needed to put<br />
the round peg into the round hole. Building a Scratch program is just<br />
that simple. We see instantly how one block may or may not fit into<br />
another block.</p>
<p>A block depicting its indent and bump can be seen in the following screenshot:</p>
<p style="text-align: center;"><img style="float:none;" src="/getting-started-with-scratch-1.4-part1_files/scratch-article2-image06.png" alt="" /></p>
<p>When we clicked on the <strong>Costumes </strong>tab, we learned that our cat had two costumes or appearances. Clicking on the costume caused the cat on the stage to change its appearance.</p>
<p>As we clicked around the sprites list, we discovered our project had two sprites: a cat and a stage. And the script we created for the cat didn&#8217;t transfer to the stage.</p>
<p>We finished the exercise by clicking on the flag. The change was subtle, but our cat appeared to take its first step when it switched to costume2.</p>
<h3>Basics of a Scratch project</h3>
<p>Inside every Scratch project, we find the following ingredients: sprites, costumes, blocks, scripts, and a stage. It&#8217;s how we mix the ingredients with our imagination that creates captivating stories, animations, and games.</p>
<p>Sprites bring our program to life, and every project has at least one. Throughout the book, we&#8217;ll learn how to add and customize sprites.</p>
<p>A sprite wears a costume. Change the costume and you change the way the sprite looks. If the sprite happens to be the stage, the costume is known as a background.</p>
<p>Blocks are just categories of instructions that include <strong>motion, looks, sound, pen, control, sensing, operators,</strong> and <strong>variables</strong>.</p>
<p>Scripts define a set of blocks that tell a sprite exactly what to do. Each block represents an instruction or piece of information that affects the sprite in some way.</p>
<h3>We&#8217;re all actors on Scratch&#8217;s stage</h3>
<p>Think of each sprite in a Scratch program as an actor. Each actor walks onto the stage and recites a set of lines from the script. How each actor interacts with another actor depends on the words the director chooses. On Scratch&#8217;s stage, every object, even the stone in the corner, is a sprite capable of contributing to the story.</p>
<p>As directors, we have full creative control.</p>
<h3>Time for action &#8211; save your work</h3>
<p>It&#8217;s a good practice to get in the habit of saving your work. Save your work early, and save it often:</p>
<ol>
<li>To save your new project, click the <strong>disk</strong> icon at the top of the Scratch window or click <strong>File | Save As</strong>.</li>
<li>A <strong>Save Project</strong> dialog box opens and asks you for a location and a <strong>New Filename</strong>.</li>
<li>Enter some descriptive information for your project by supplying the <strong>Project author</strong> and notes <strong>About this project</strong> in the fields provided.</li>
</ol>
<p><img src="/getting-started-with-scratch-1.4-part1_files/scratch-article2-image07.png" alt="" width="480" height="258" /></p>
<h2>Set the cat in motion</h2>
<p>Even though our script contains only two blocks, we have a problem. When we click on the flag, the sprite switches to a different costume and stops. If we try to click on the flag again, nothing appears to happen, and we can&#8217;t get back to the first costume unless we go to the <strong>Costumes</strong> tab and select <strong>costume1</strong>. That&#8217;s not fun.</p>
<p>In our next exercise, we&#8217;re going to switch between both costumes and create a lively animation.</p>
<hr size="1" noshade="noshade" />Scratch 1.4: Beginner&#8217;s Guide</p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td width="99" valign="top"><a onclick="javascript: pageTracker._trackPageview('/outgoing/packtpub.com');" href="http://www.packtpub.com/scratch-1-4-beginners-guide/mid/280709dmggns?utm_source=scratchguide.com&amp;utm_medium=affiliate&amp;utm_content=blog&amp;utm_campaign=mdb_000050"><img class="left" title="Scratch 1.4: Beginner’s Guide" src="/getting-started-with-scratch-1.4-part1_files/1847196764.png" border="0" alt="Scratch 1.4: Beginner’s Guide" width="99" height="123" /></a></td>
<td valign="top">
<ul>
<li>Learn to program while creating interactive stories, games, and multimedia projects using Scratch</li>
<li>Create interactive stories, games, and multimedia projects that you can reuse in your own classroom</li>
<li>Learn computer programming basics &#8211; no computer science degree required</li>
<li>Connect with the Scratch community for inspiration, advice, and collaboration</li>
<li>Provides hands-on projects that help you learn by experiment and play</li>
</ul>
<p><a onclick="javascript: pageTracker._trackPageview('/outgoing/packtpub.com');" href="http://www.packtpub.com/scratch-1-4-beginners-guide/mid/280709dmggns?utm_source=scratchguide.com&amp;utm_medium=affiliate&amp;utm_content=blog&amp;utm_campaign=mdb_000050">http://www.packtpub.com/scratch-1-3-beginners-guide/book</a></td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" /><strong>Time for action &#8211; a big step</strong></p>
<p>We will continue working with our script from the previous example:</p>
<ol>
<li>From the blocks palette, select <strong>Motion</strong>.</li>
<li>Drag the <strong>change x by</strong> block to the script area for <strong>Sprite1</strong> and snap it in place at the end of the script. See the following screenshot for reference:
<p style="text-align: center;"><img style="float:none;" src="/getting-started-with-scratch-1.4-part1_files/scratch-article2-image08.png" alt="" /></p>
</li>
<li>Double-click on the script and watch your sprite move across the stage.
<p style="margin-left: 40px; margin-right: 40px;"><em>Double-clicking on the script runs through each block of the script.</em></p>
</li>
<li>The <strong>change x by</strong> block has an number field with a default value of <strong>10</strong>. This number controls how far the sprite moves. Change <strong>10</strong> to <strong>20</strong>.</li>
<li>Double-click on the script again.</li>
<li>From the <strong>motion</strong> palette, drag the <strong>change y by</strong> block and add it to the end of your script.</li>
<li>Change the value in the <strong>change y by</strong> block to a negative number, such as <strong>-30</strong>.</li>
<li>Click the flag.
<p style="text-align: center;"><img style="float:none;" src="/getting-started-with-scratch-1.4-part1_files/scratch-article2-image09.png" alt="" /></p>
</li>
</ol>
<h4><em>What just happened?</em></h4>
<p>We added the <strong>change x by </strong>block to our script to make the cat move horizontally toward the right side of the stage. As we increased the value, our sprite moved further across the stage each time.</p>
<p>Next, we added the <strong>change y by </strong>block and gave it a negative value. When we clicked the flag, the sprite continued to move horizontally to the right, but it also moveddown.</p>
<p style="margin-left: 40px; margin-right: 40px;"><em>The<br />
numeric x or y values found on several of the motion blocks measure<br />
pixels. The stage is 480 pixels wide and 360 pixels tall.</em></p>
<h3>Coordinating a sprite&#8217;s location</h3>
<p>Scratch uses an <strong>X</strong> and <strong>Y </strong>axis to divide the screen into quadrants. Enter a positive number for X, and the sprite moves to the right. Similarly, enter a negative number for X, and the sprite moves to the left, or backward. A positive Y value makes the sprite climb, while a negative Y value makes the sprite fall.</p>
<p>The unit of measure on our coordinate system is pixels. Each sprite on the stage has an <strong>X</strong> and <strong>Y</strong> coordinate that allows you to locate it, but it also allows you to send a sprite to a specific coordinate.</p>
<p>As we&#8217;ll discover later, even the mouse pointer has an X and Y coordinate that allows us to precisely locate the pointer.</p>
<h3>Double-click control</h3>
<p>So far we&#8217;ve seen two ways to control the sprite on the stage. We can build a script that uses a control block, such as the flag. Or we can double-click on a block or set of blocks to run a command on the sprite.</p>
<p>The ability to run an individual block against a sprite gives us a chance to observe the behavior of the block before we add the block to our script. It&#8217;s a great way to test and learn.</p>
<p>Double-clicking on a block works if we have one, ten, or an infinite number of blocks stacked together.</p>
<h3>Time for action &#8211; in motion forever</h3>
<p>So far the cat has moved incrementally across the screen by a set number of pixels and has stopped. Now, we&#8217;re going to introduce the idea that the cat can stay in motion forever.</p>
<ol>
<li>From the <strong>Control</strong> palette, drag the <strong>forever</strong> block onto the stack of blocks. Position it in such a way that it snaps in place between the <strong>when flag clicked</strong> and <strong>switch to costume</strong> blocks.</li>
<li>Double-click the stack of blocks and watch the cat disappear from the stage.</li>
<li>From the <strong>Motion</strong> palette, drag the if on <strong>edge, bounce</strong> block and snap it to the bottom of the <strong>change y by</strong> block. Now watch the cat reappear and bounce around the bottom-right corner of the stage.</li>
<li>Single-click on the script to stop the cat.</li>
</ol>
<h4><em>What just happened?</em></h4>
<p>We wrapped our entire script in a forever block. In programming lingo, we put our script into a loop. However, that sent our sprite racing off the screen, so we had to tell our sprite to bounce when it hit the edge of the stage.</p>
<p>If you carried out the steps in the exercise as described, you noticed that as soon as you placed the <strong>if on edge, bounce</strong> block into your script, the sprite reappeared.</p>
<p style="margin-left: 40px; margin-right: 40px;"><em>You can add blocks to the loop and change the values as the script runs and the sprite automatically adjusts to the new values.</em></p>
<p>Even though the sprite reappeared on the screen, it&#8217;s trapped in the corner of the stage. It&#8217;s stuck in a loop.</p>
<h5>Loops play it again</h5>
<p>Whenever we need to repeat an action or continually check for a condition within a program, we use a loop. The forever block represents an infinite loop. The blocks inside the loop will run as long as the Scratch program is running.</p>
<p>As we move through the book, we will encounter other types of loops. Examples include loops that run a set of blocks for a set number of times and loops that run only if a specified condition is met.</p>
<h3>Time for action &#8211; get out of the corner</h3>
<p>We need to get the cat out of the corner and moving across the stage in some kind of orderly fashion. We&#8217;ll do that by replacing the <strong>change x by</strong> and <strong>change y by</strong> blocks:</p>
<ol>
<li>Click on the scissors icon located on the toolbar above the stage to activate the scissors tool.
<p style="text-align: center;"><img style="float:none;" src="/getting-started-with-scratch-1.4-part1_files/scratch-article2-image10.png" alt="" /></p>
</li>
<li>Move the scissors over the <strong>change x by</strong> block until it is outlined in a red square. Click your left mouse button to delete the block.
<p style="text-align: center;"><img style="float:none;" src="/getting-started-with-scratch-1.4-part1_files/scratch-article2-image11.png" alt="" /></p>
</li>
<li>Similarly, delete the <strong>change y by</strong> block.</li>
<li>From the <strong>Motion</strong> palette, drag the <strong>move 10 steps</strong> block into your script and snap it in place before the <strong>if on edge, bounce</strong> block.</li>
<li>From the <strong>Looks</strong> palette, snap the <strong>switch to costume</strong> block into place after the <strong>move 10 steps</strong> block. Double-click the script to set it in motion. Select <strong>costume1</strong> from the list of costumes.</li>
<li>Add a second <strong>switch to costume</strong> block before the <strong>move 10 steps</strong> block. Select <strong>costume2</strong> from the list of costumes.
<p style="margin-left: 40px; margin-right: 40px;"><em>The<br />
drop-down menu on the stack of blocks is sensitive. Click directly on<br />
the black triangle to display the available selections.</em></li>
<li>If the cat stopped moving, double-click the script again. It should be running upside down!<br />
<img src="/getting-started-with-scratch-1.4-part1_files/scratch-article2-image12.png" alt="" width="480" height="203" /></li>
<li>Let&#8217;s change the rotation of the sprite. Information about the current sprite displays directly above the script area. To the left of the sprite are three directional buttons: <strong>can rotate, only face left-right</strong>, and <strong>don&#8217;t rotate</strong>.
<p style="margin-left: 40px; margin-right: 40px;"><em>Many buttons in Scratch will display a tool tip when you hover your mouse over the button. Try it with the rotation buttons.</em></p>
</li>
<li>Click on the <strong>only face left-right</strong> rotation button, and now our sprite doesn&#8217;t run upside down when it bounces off the side of the stage.</li>
</ol>
<h4><em>What just happened?</em></h4>
<p>The <strong>move 10 steps </strong>block made the cat move in the direction it was facing, and when it<br />
bounced off the edge of the stage, the cat rotated so that it faced the other way. As the cat rotated, it turned upside down.</p>
<p>When we inserted the <strong>switch to costume</strong> block and set the value to <strong>costume1</strong>, the cat appeared to run. What really happened is that at every ten steps, our script displayed a different look as the cat moved across the screen. Our trick was subtle; as we changed the look of the cat, we created the appearance of running.</p>
<p>But we couldn&#8217;t let the cat run upside down forever, so we adjusted the rotation so that when the cat hit the edge of the stage, it flipped 180 degrees and kept running.</p>
<h4>Have a go hero</h4>
<p>Make the cat run backward across the screen.</p>
<p>Hint: Set the rotation of the sprite to <strong>don&#8217;t rotate</strong>.</p>
<h4>Undo an action</h4>
<p>If you deleted something you shouldn&#8217;t have, there is an <strong>Undo</strong> button at the top of the Scratch window. Clicking <strong>Undo</strong> attaches the last block you deleted to your cursor, and you&#8217;re able to snap it in place on the script.</p>
<p>You can only <strong>Undo</strong> the last action; Scratch doesn&#8217;t have an unlimited undo capabilities.</p>
<h2>Summary</h2>
<p>Feel warmed up? This part of the article helped us feel comfortable working with Scratch by covering some basic concepts. Each Scratch project contains sprites with costumes, scripts, blocks, and a stage with backgrounds. We built a couple of sample scripts to demonstrate how we can control the sprites in a project. For example, we used motion to move the sprites and forever loops to keep the sprite moving.</p>
<hr size="1" noshade="noshade" />Scratch 1.4: Beginner&#8217;s Guide</p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td width="99" valign="top"><a onclick="javascript: pageTracker._trackPageview('/outgoing/packtpub.com');" href="http://www.packtpub.com/scratch-1-4-beginners-guide/mid/280709dmggns?utm_source=scratchguide.com&amp;utm_medium=affiliate&amp;utm_content=blog&amp;utm_campaign=mdb_000050"><img class="left" title="Scratch 1.4: Beginner’s Guide" src="/getting-started-with-scratch-1.4-part1_files/1847196764.png" border="0" alt="Scratch 1.4: Beginner’s Guide" width="99" height="123" /></a></td>
<td valign="top">
<ul>
<li>Learn to program while creating interactive stories, games, and multimedia projects using Scratch</li>
<li>Create interactive stories, games, and multimedia projects that you can reuse in your own classroom</li>
<li>Learn computer programming basics &#8211; no computer science degree required</li>
<li>Connect with the Scratch community for inspiration, advice, and collaboration</li>
<li>Provides hands-on projects that help you learn by experiment and play</li>
</ul>
<p><a onclick="javascript: pageTracker._trackPageview('/outgoing/packtpub.com');" href="http://www.packtpub.com/scratch-1-4-beginners-guide/mid/280709dmggns?utm_source=scratchguide.com&amp;utm_medium=affiliate&amp;utm_content=blog&amp;utm_campaign=mdb_000050">http://www.packtpub.com/scratch-1-3-beginners-guide/book</a></td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" />
]]></content:encoded>
			<wfw:commentRss>http://www.scratchguide.com/scratch-programming-introduction-the-basics/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
