1 00:00:00,000 --> 00:00:03,451 [MUSIC PLAYING] 2 00:00:03,451 --> 00:00:17,033 3 00:00:17,033 --> 00:00:19,200 BRIAN YU: Welcome back, everyone, to An Introduction 4 00:00:19,200 --> 00:00:20,580 to Programming with Scratch. 5 00:00:20,580 --> 00:00:23,880 And last time we took a look at the fundamentals of programming-- 6 00:00:23,880 --> 00:00:26,160 putting together a sequence of instructions 7 00:00:26,160 --> 00:00:30,345 that we called Functions by assembling these different colored Scratch blocks. 8 00:00:30,345 --> 00:00:32,970 And by putting together these different colored Scratch blocks, 9 00:00:32,970 --> 00:00:35,220 we were able to bring our projects to life. 10 00:00:35,220 --> 00:00:38,070 We were able to take characters, or sprites, on the stage, 11 00:00:38,070 --> 00:00:42,240 and have them move around, or draw pictures, and play sound, and more. 12 00:00:42,240 --> 00:00:45,060 And so today, let's take those concepts of programming 13 00:00:45,060 --> 00:00:47,440 and build upon them a little bit more. 14 00:00:47,440 --> 00:00:50,640 I'll go ahead and open up Scratch again, and let's start with a program 15 00:00:50,640 --> 00:00:51,820 that we've seen before. 16 00:00:51,820 --> 00:00:54,900 I'll go ahead and go into the Looks section of the blocks 17 00:00:54,900 --> 00:00:58,870 and pull out this Say Hello For 2 Seconds block. 18 00:00:58,870 --> 00:01:01,290 And as you might recall, when I click on this block 19 00:01:01,290 --> 00:01:04,290 to run this Stack, or script of code, you'll 20 00:01:04,290 --> 00:01:08,130 see that my cat over on the stage says "hello" for two seconds, 21 00:01:08,130 --> 00:01:09,510 and then it stops. 22 00:01:09,510 --> 00:01:11,940 And so that seems to work well, but notice 23 00:01:11,940 --> 00:01:16,110 that in order to run this program, I had to click on the code 24 00:01:16,110 --> 00:01:18,720 that I wanted the cat to run. 25 00:01:18,720 --> 00:01:21,590 And that might be fine, but if you've used programs on your computer 26 00:01:21,590 --> 00:01:23,760 or on your phone before, then you probably 27 00:01:23,760 --> 00:01:26,940 haven't specifically told the program which part of the code 28 00:01:26,940 --> 00:01:28,290 you want it to run when. 29 00:01:28,290 --> 00:01:31,320 You open up an app and some code runs, or you click a button 30 00:01:31,320 --> 00:01:34,260 and some code runs, or you type something onto your keyboard 31 00:01:34,260 --> 00:01:36,270 and some code runs-- you're not specifically 32 00:01:36,270 --> 00:01:40,950 pointing to what lines of code in a program you generally want to run. 33 00:01:40,950 --> 00:01:44,070 And one other problem here might be what might 34 00:01:44,070 --> 00:01:47,460 happen if I have multiple scripts across multiple sprites maybe. 35 00:01:47,460 --> 00:01:50,160 Imagine that it's not just the cat saying "hello, " 36 00:01:50,160 --> 00:01:52,080 but the cat talking to-- 37 00:01:52,080 --> 00:01:55,270 let's pick another sprite, let's pick the dinosaur. 38 00:01:55,270 --> 00:01:57,630 So I'll go into Animals and choose the dinosaur, 39 00:01:57,630 --> 00:02:00,850 and maybe I want these two to say hello to each other. 40 00:02:00,850 --> 00:02:04,110 So I'll move it so that the cat and the dinosaur are next to each other, 41 00:02:04,110 --> 00:02:07,860 and I want to turn the dinosaur around so that they're facing each other. 42 00:02:07,860 --> 00:02:11,490 And I can do that recall by going into the direction for the dinosaur 43 00:02:11,490 --> 00:02:16,050 and having it face the left instead of facing the right. 44 00:02:16,050 --> 00:02:18,390 And now it seems like the dinosaurs upside down, 45 00:02:18,390 --> 00:02:22,350 so I just need to remember to change the rotation style to left and right 46 00:02:22,350 --> 00:02:24,720 instead of all around-- and so now the cat 47 00:02:24,720 --> 00:02:26,830 and the dinosaur are facing each other. 48 00:02:26,830 --> 00:02:31,140 And if I want them both to say hello to each other, well then this dinosaur-- 49 00:02:31,140 --> 00:02:32,970 notice the dinosaur is now selected-- 50 00:02:32,970 --> 00:02:36,640 is also going to need a block that lets it say hello. 51 00:02:36,640 --> 00:02:41,430 So I'll also give it a block that says Say Hello For 2 Seconds-- 52 00:02:41,430 --> 00:02:44,310 but now if I want the cat to say hello to the dinosaur, 53 00:02:44,310 --> 00:02:47,025 well, then I'll need to go to the cat, click the Say Hello block, 54 00:02:47,025 --> 00:02:49,650 but then very quickly click on the dinosaur and click Say Hello 55 00:02:49,650 --> 00:02:52,970 too so that they can both say hello to each other. 56 00:02:52,970 --> 00:02:56,220 It was a bit tedious for me to have to quickly jump back and forth between two 57 00:02:56,220 --> 00:02:59,730 sprites, and you could imagine that at a more complex project where 58 00:02:59,730 --> 00:03:02,760 a sprite might have multiple different scripts that we want to run, 59 00:03:02,760 --> 00:03:04,440 or you might have many more sprites-- 60 00:03:04,440 --> 00:03:08,130 it's not going to be possible for me to, in any reasonable amount of time, 61 00:03:08,130 --> 00:03:12,300 go to all of the different sprites and start up all of the different blocks 62 00:03:12,300 --> 00:03:13,410 that I want to run. 63 00:03:13,410 --> 00:03:16,510 It would be better if I could just say, let's start the project, 64 00:03:16,510 --> 00:03:21,300 and when the project starts then that I want all of these scripts of code 65 00:03:21,300 --> 00:03:22,830 to run automatically. 66 00:03:22,830 --> 00:03:25,810 And we can do just that via this button-- 67 00:03:25,810 --> 00:03:27,790 it's in the upper right of the Scratch window-- 68 00:03:27,790 --> 00:03:28,770 this is the flag. 69 00:03:28,770 --> 00:03:30,990 And generally when you click on this green flag, 70 00:03:30,990 --> 00:03:34,560 that marks the start of your Scratch project. 71 00:03:34,560 --> 00:03:37,440 Of course right now, when I click on this green flag-- 72 00:03:37,440 --> 00:03:39,810 nothing's happening, and so here is where 73 00:03:39,810 --> 00:03:42,240 we're going to introduce a new concept in programming 74 00:03:42,240 --> 00:03:44,100 and that's the concept of an Event. 75 00:03:44,100 --> 00:03:47,460 And we can see the Event blocks as one of the options along the left hand 76 00:03:47,460 --> 00:03:49,470 side of the Scratch window. 77 00:03:49,470 --> 00:03:53,430 And an Event is just something that happens inside of our program 78 00:03:53,430 --> 00:03:55,710 that we could have some code respond to. 79 00:03:55,710 --> 00:03:57,660 We could say that, when something happens-- 80 00:03:57,660 --> 00:03:59,850 for example, when the flag is clicked-- 81 00:03:59,850 --> 00:04:02,610 then I want the cat to say hello for two seconds, 82 00:04:02,610 --> 00:04:07,000 or I want the dinosaur to say hello for two seconds as well. 83 00:04:07,000 --> 00:04:11,670 And so, we do have this very first Event block here, When Flag Clicked, 84 00:04:11,670 --> 00:04:15,000 and I'm going to take this block and drag it on top 85 00:04:15,000 --> 00:04:18,510 of the Say Hello For 2 Seconds block. 86 00:04:18,510 --> 00:04:22,950 And so now I've attached my code to a particular Event-- 87 00:04:22,950 --> 00:04:25,320 this block here is called When Flag Clicked. 88 00:04:25,320 --> 00:04:28,410 It means that when this Event happens, when the flag is clicked, 89 00:04:28,410 --> 00:04:31,800 we are going to run all of the code that is attached beneath it. 90 00:04:31,800 --> 00:04:34,740 And notice that nothing can be attached on top of this event 91 00:04:34,740 --> 00:04:38,970 block-- this event is the beginning of the script of these blocks of code 92 00:04:38,970 --> 00:04:40,110 that I want to now run. 93 00:04:40,110 --> 00:04:42,600 And so now, when I click on the green flag, 94 00:04:42,600 --> 00:04:46,530 the dinosaur is going to respond by saying hello for two seconds. 95 00:04:46,530 --> 00:04:49,920 So I go back to the project here, click on the green flag, 96 00:04:49,920 --> 00:04:54,510 and the dinosaur says "hello. " And now if I want the cat to say hello too, 97 00:04:54,510 --> 00:04:57,750 well, then all I need to do is click on the cat in the sprite chooser down 98 00:04:57,750 --> 00:05:01,690 below, and add the When Flag Clicked Event to it as well. 99 00:05:01,690 --> 00:05:06,240 So I'll take the When Flag Clicked block, drag it on top of the Say block, 100 00:05:06,240 --> 00:05:07,042 and now-- 101 00:05:07,042 --> 00:05:08,250 when I click the green flag-- 102 00:05:08,250 --> 00:05:11,910 I just have to click once and both the cat and the dinosaur 103 00:05:11,910 --> 00:05:15,690 are going to say hello rather than me having to click one block immediately 104 00:05:15,690 --> 00:05:20,140 very quickly, jump to another sprite, and then click on the block as well. 105 00:05:20,140 --> 00:05:22,050 And the nice thing now is that someone can 106 00:05:22,050 --> 00:05:25,668 run my project without ever looking at my code and the code will still work. 107 00:05:25,668 --> 00:05:27,960 They don't have to know which blocks to click on-- they 108 00:05:27,960 --> 00:05:30,600 can just click on the green flag and see the project work. 109 00:05:30,600 --> 00:05:32,433 And in fact, that's what happens if you were 110 00:05:32,433 --> 00:05:35,100 to share your Scratch project on Scratch's website-- sending it 111 00:05:35,100 --> 00:05:37,170 to friends or family for example. 112 00:05:37,170 --> 00:05:40,470 They'll usually just see your project without seeing the code at first, 113 00:05:40,470 --> 00:05:43,680 and they can run your project, and see that both the cat-- 114 00:05:43,680 --> 00:05:47,100 and the dinosaur, in this case, are going to say hello. 115 00:05:47,100 --> 00:05:50,550 So these are Events, where when something happens in the project, 116 00:05:50,550 --> 00:05:54,540 we can respond to that happening by having some blocks of code run. 117 00:05:54,540 --> 00:05:57,368 But there are other Events that we can use as well-- 118 00:05:57,368 --> 00:05:59,160 and let's take a look at another Event now. 119 00:05:59,160 --> 00:06:03,330 I'll delete the cat and the dinosaur for now, and let's add a new sprite-- 120 00:06:03,330 --> 00:06:07,240 let's pick an animal, and let's go back to the duck here. 121 00:06:07,240 --> 00:06:11,040 So we have the duck and the Event that we'll take a look at now 122 00:06:11,040 --> 00:06:14,820 is this one here-- it's called When This Sprite Clicked. 123 00:06:14,820 --> 00:06:17,670 Meaning, when this sprite is clicked on, some code 124 00:06:17,670 --> 00:06:20,670 is going to run in response to the fact that I've 125 00:06:20,670 --> 00:06:22,683 clicked on the duck in this case. 126 00:06:22,683 --> 00:06:24,600 And I can have anything happen, and maybe what 127 00:06:24,600 --> 00:06:27,540 I'll have happened just for now is I'll go into Motion, 128 00:06:27,540 --> 00:06:31,500 and I'll have the duck go to a random position. 129 00:06:31,500 --> 00:06:36,010 So every time I click on the duck, it's going to go now to a random position. 130 00:06:36,010 --> 00:06:39,687 So go into the stage, I'll click on the duck, and the duck moves. 131 00:06:39,687 --> 00:06:42,270 I'll click the duck again and it moves, I click the duck again 132 00:06:42,270 --> 00:06:45,270 and it moves-- and If I wanted it to move a little bit more smoothly, 133 00:06:45,270 --> 00:06:49,050 remember that Go To will immediately jump to a random position. 134 00:06:49,050 --> 00:06:53,940 But I could instead, by removing this block and replacing it with this one, 135 00:06:53,940 --> 00:06:57,480 have the duck glide to a random position-- take one second 136 00:06:57,480 --> 00:07:00,030 and just glide smoothly to a different position. 137 00:07:00,030 --> 00:07:02,190 Now every time I click on the duck, you'll 138 00:07:02,190 --> 00:07:08,160 notice the duck glide across the stage to a different random position 139 00:07:08,160 --> 00:07:09,300 on that stage. 140 00:07:09,300 --> 00:07:13,110 And it's responding, again, not to when I'm clicking on the code itself, 141 00:07:13,110 --> 00:07:15,690 but when I'm clicking on the duck, and the duck 142 00:07:15,690 --> 00:07:17,430 is responding because it's an Event. 143 00:07:17,430 --> 00:07:20,610 The Event is when the sprite is clicked on, we're going to glide. 144 00:07:20,610 --> 00:07:25,290 And what you'll notice too is that, on the left side of the Scratch window, 145 00:07:25,290 --> 00:07:26,790 when the sprite is clicked-- 146 00:07:26,790 --> 00:07:30,600 you'll see this script light up to tell us and indicate to us 147 00:07:30,600 --> 00:07:32,580 that this script is currently running. 148 00:07:32,580 --> 00:07:36,120 Right now it's not running, but notice that as soon as I click on the duck 149 00:07:36,120 --> 00:07:40,770 it lights up for one second as the duck is moving, and then it stops being lit. 150 00:07:40,770 --> 00:07:44,490 And while it's lit, that's when we know that this particular script happens 151 00:07:44,490 --> 00:07:45,850 to be running. 152 00:07:45,850 --> 00:07:49,740 And so the ability to have sprites respond when we click on something-- 153 00:07:49,740 --> 00:07:51,750 on the stage, when we click on that sprite-- 154 00:07:51,750 --> 00:07:55,500 on the stage gives us a lot of flexibility and creative potential 155 00:07:55,500 --> 00:07:58,110 for creating new types of user interfaces-- 156 00:07:58,110 --> 00:08:01,790 for letting the user interact with our project in different ways. 157 00:08:01,790 --> 00:08:04,260 In fact, you might think of this as something like a button 158 00:08:04,260 --> 00:08:06,593 where, when you click on a button on a computer program, 159 00:08:06,593 --> 00:08:10,180 something happens in response to clicking on that button. 160 00:08:10,180 --> 00:08:12,330 And now that we have this Event, When Clicked, 161 00:08:12,330 --> 00:08:16,860 we can create buttons of our own inside of our Scratch projects. 162 00:08:16,860 --> 00:08:18,210 And so let's try just that-- 163 00:08:18,210 --> 00:08:20,730 I'll get rid of the duck for now, and let's add 164 00:08:20,730 --> 00:08:23,550 some backdrops that we might want for our project. 165 00:08:23,550 --> 00:08:26,430 I'll add a new backdrop and-- 166 00:08:26,430 --> 00:08:29,578 I like the Arctic backdrop, so we'll pick that one first-- 167 00:08:29,578 --> 00:08:32,370 and let's choose a couple that I might like to use in this project. 168 00:08:32,370 --> 00:08:36,360 So I'll choose another one, and let's go now to the jungle-- 169 00:08:36,360 --> 00:08:39,090 that one seems interesting, slightly different. 170 00:08:39,090 --> 00:08:43,289 And we'll do one more, and we'll go back to the underwater one 171 00:08:43,289 --> 00:08:45,960 that we were using with the fish before. 172 00:08:45,960 --> 00:08:49,410 And so I've got three different backdrops that are part of my project-- 173 00:08:49,410 --> 00:08:51,960 I've got the Arctic backdrop, I've got the jungle backdrop, 174 00:08:51,960 --> 00:08:53,940 and I've got the underwater backdrop here. 175 00:08:53,940 --> 00:08:57,090 Of course, only one backdrop can be active at one time-- 176 00:08:57,090 --> 00:08:58,470 we can switch between them-- 177 00:08:58,470 --> 00:09:01,150 but only one can be there at any given time. 178 00:09:01,150 --> 00:09:04,830 So let's add some buttons to let the user control which 179 00:09:04,830 --> 00:09:07,650 backdrop is going to be selected. 180 00:09:07,650 --> 00:09:10,370 I will add a sprite, and notice that there 181 00:09:10,370 --> 00:09:13,380 are a couple of different types of buttons that I can choose from-- 182 00:09:13,380 --> 00:09:16,360 I'll go ahead and choose this button, Button2. 183 00:09:16,360 --> 00:09:22,070 And I'll drag the button down to maybe the left side of the screen-- 184 00:09:22,070 --> 00:09:23,720 and let's first modify the button-- 185 00:09:23,720 --> 00:09:27,630 I'll go to the Costumes and I'll add some text to the button. 186 00:09:27,630 --> 00:09:32,220 I'll add some text and the text will say Arctic, for example-- 187 00:09:32,220 --> 00:09:37,510 I'll select the text, change its color, and I'll make sure 188 00:09:37,510 --> 00:09:40,060 that this is by clicking on the arrow. 189 00:09:40,060 --> 00:09:43,620 Make the text a little bit bigger and center 190 00:09:43,620 --> 00:09:46,750 the text approximately on the button-- 191 00:09:46,750 --> 00:09:50,620 and so now I have one button that says Arctic on my project. 192 00:09:50,620 --> 00:09:53,440 But of course, when I click on the Arctic button, 193 00:09:53,440 --> 00:09:55,580 nothing's happening just yet. 194 00:09:55,580 --> 00:09:58,652 So let's add an Event such that, when I click on this button, 195 00:09:58,652 --> 00:09:59,860 something is going to happen. 196 00:09:59,860 --> 00:10:04,300 I'll go back into Events, the Event I want is When This Sprite Clicked. 197 00:10:04,300 --> 00:10:07,240 And when this sprite is clicked, what do I want to happen? 198 00:10:07,240 --> 00:10:10,660 Well, I want the backdrop to change to the Arctic backdrop. 199 00:10:10,660 --> 00:10:13,710 The backdrop changing, that has to do with the look of the project, 200 00:10:13,710 --> 00:10:16,060 so we'll go to the Look section of blocks 201 00:10:16,060 --> 00:10:22,300 and let's switch backdrop to Arctic. 202 00:10:22,300 --> 00:10:26,350 And now when I click on the button, you'll notice the backdrop change. 203 00:10:26,350 --> 00:10:28,840 I clicked on the button and, because we have that Event, 204 00:10:28,840 --> 00:10:31,550 it's responding to us as well. 205 00:10:31,550 --> 00:10:34,880 And so now let's add buttons for each of the other backdrops 206 00:10:34,880 --> 00:10:36,880 that I might want to switch to in this project-- 207 00:10:36,880 --> 00:10:39,255 and I could do that by doing exactly what I've just done, 208 00:10:39,255 --> 00:10:42,250 by adding a new sprite, choosing the button again, adding some text. 209 00:10:42,250 --> 00:10:44,710 But it'll be a little bit easier actually for now 210 00:10:44,710 --> 00:10:49,520 to just duplicate the sprite that I already have-- this button here. 211 00:10:49,520 --> 00:10:53,110 So I'll go ahead and Right-click or Control-click on the sprite and click 212 00:10:53,110 --> 00:10:54,160 Duplicate-- 213 00:10:54,160 --> 00:10:58,180 I've got another button, these are just called Button2 and Button3 for now. 214 00:10:58,180 --> 00:11:00,290 It'll be a little bit nicer if I give them names-- 215 00:11:00,290 --> 00:11:07,820 I'll call this button Arctic Button, and I'll call this button Jungle Button. 216 00:11:07,820 --> 00:11:09,090 What do I need to do? 217 00:11:09,090 --> 00:11:12,510 Well, let's go into Costumes and first change this text. 218 00:11:12,510 --> 00:11:18,990 Let's change the text to Jungle, recenter the text a little bit there, 219 00:11:18,990 --> 00:11:23,080 and now when this sprite is clicked-- when the jungle button is clicked-- 220 00:11:23,080 --> 00:11:27,330 I can switch the backdrop to the jungle instead. 221 00:11:27,330 --> 00:11:30,090 And notice that in the upper right portion of the Code Editor, 222 00:11:30,090 --> 00:11:34,020 you'll always see a slightly transparent image of what sprite you're currently 223 00:11:34,020 --> 00:11:37,500 working on-- in case you ever forget, it's also selected down below-- 224 00:11:37,500 --> 00:11:41,400 but right now I can tell because I see this slightly faded Jungle Button 225 00:11:41,400 --> 00:11:45,370 that right now I'm editing the code for this Jungle Button. 226 00:11:45,370 --> 00:11:49,050 And now when I click on the button, the backdrop changes to the jungle-- 227 00:11:49,050 --> 00:11:54,450 and I can drag this so that it's underneath the Arctic Button. 228 00:11:54,450 --> 00:11:58,980 And let's add one more button by Control-click and duplicate this 229 00:11:58,980 --> 00:11:59,650 button-- 230 00:11:59,650 --> 00:12:03,810 I'll change the name of the button to Underwater Button, 231 00:12:03,810 --> 00:12:07,290 and now we'll go into costumes-- and change the text, 232 00:12:07,290 --> 00:12:08,815 change this to Underwater. 233 00:12:08,815 --> 00:12:11,940 The text is a little too long, so I'll need to make it a bit smaller to fit 234 00:12:11,940 --> 00:12:13,290 on the button-- that's OK-- 235 00:12:13,290 --> 00:12:15,750 I can just click on the arrow and that will 236 00:12:15,750 --> 00:12:21,820 let me drag and resize various different elements on my costume. 237 00:12:21,820 --> 00:12:24,130 So now I've got a button that says Underwater, 238 00:12:24,130 --> 00:12:27,430 and I'll switch back to the Code tab now instead of the Costumes tab. 239 00:12:27,430 --> 00:12:29,470 And now, when this sprite is clicked, let's 240 00:12:29,470 --> 00:12:34,480 switch the backdrop to Underwater 1, which was the name of that backdrop. 241 00:12:34,480 --> 00:12:38,930 And now when I click Underwater, we switch to the underwater backdrop. 242 00:12:38,930 --> 00:12:41,130 I'll stack these buttons on top of each other-- 243 00:12:41,130 --> 00:12:44,330 and now what I have are three buttons that the user can click on 244 00:12:44,330 --> 00:12:46,610 to switch between the various different backdrops. 245 00:12:46,610 --> 00:12:49,780 Depending on which button they click, they'll 246 00:12:49,780 --> 00:12:53,830 be able to see the backdrop respond to the buttons 247 00:12:53,830 --> 00:12:57,070 that they're clicking on as well. 248 00:12:57,070 --> 00:12:59,010 And so using this we really have the ability 249 00:12:59,010 --> 00:13:02,280 to let the user interact with the stage-- click on the stage 250 00:13:02,280 --> 00:13:04,107 and see something actually happen. 251 00:13:04,107 --> 00:13:05,940 And I'll show you one more example of this-- 252 00:13:05,940 --> 00:13:09,210 I'll get rid of our buttons for now, and I'll go back to backdrops, 253 00:13:09,210 --> 00:13:12,720 and go ahead and switch us back to the plain white backdrop. 254 00:13:12,720 --> 00:13:16,290 But let's add some sprites that the user might interact with, 255 00:13:16,290 --> 00:13:17,740 I'll go ahead and add sprites. 256 00:13:17,740 --> 00:13:19,650 And so far I've mostly been using animals, 257 00:13:19,650 --> 00:13:24,810 but let's jump to the Music tab for now and add a few instruments. 258 00:13:24,810 --> 00:13:28,300 Let's add a snare drum, and let's add one more-- 259 00:13:28,300 --> 00:13:34,210 let's add the conga drums, and let's add one more-- 260 00:13:34,210 --> 00:13:38,040 let's add the cymbal. 261 00:13:38,040 --> 00:13:40,000 So we'll go ahead and move these around-- 262 00:13:40,000 --> 00:13:42,720 I've got three different drums. 263 00:13:42,720 --> 00:13:46,260 And now, when I click on each of them-- let me go to Events 264 00:13:46,260 --> 00:13:50,880 and drag out this When This Sprite Clicked button. 265 00:13:50,880 --> 00:13:55,050 We'll go into Sound and we can play a sound, 266 00:13:55,050 --> 00:13:57,360 and I'll play-- we have a bunch of different snare 267 00:13:57,360 --> 00:14:00,580 drum sounds I can choose from-- which is like the tap snare, for example. 268 00:14:00,580 --> 00:14:04,440 And let's add a sound to each of these various different drums 269 00:14:04,440 --> 00:14:07,470 for when I click on that sprite-- so for the conga drums, 270 00:14:07,470 --> 00:14:12,540 I'll go back to Events, When This Sprite Clicked, I go back to Sounds 271 00:14:12,540 --> 00:14:14,340 and say let's play a sound. 272 00:14:14,340 --> 00:14:17,700 Let's play the-- let's go with the high conga sound-- 273 00:14:17,700 --> 00:14:22,800 and finally we go into the cymbal, and say-- now when the cymbal is clicked, 274 00:14:22,800 --> 00:14:28,230 let's go ahead and play the sound crash cymbal. 275 00:14:28,230 --> 00:14:32,340 And just with that, with two blocks of code for each of my three drums-- 276 00:14:32,340 --> 00:14:35,200 one Event and one block that plays a sound-- 277 00:14:35,200 --> 00:14:38,250 now I have a drum kit that I've built just using Scratch. 278 00:14:38,250 --> 00:14:48,707 When I click on any one of these drums, you hear some sounds, 279 00:14:48,707 --> 00:14:51,040 and you can have fun with that adding other instruments, 280 00:14:51,040 --> 00:14:54,130 playing music-- remember we have that music extension that we took 281 00:14:54,130 --> 00:14:57,430 a look at last time that gives you various different options for playing 282 00:14:57,430 --> 00:15:00,130 notes and playing other instrumental sounds. 283 00:15:00,130 --> 00:15:04,480 And so you could create some music, and let the user create some music just 284 00:15:04,480 --> 00:15:08,150 by clicking on things inside of their Scratch project. 285 00:15:08,150 --> 00:15:12,080 And so that then is the power of responding to a Click Event-- 286 00:15:12,080 --> 00:15:15,290 clicking is an Event, the user clicking somewhere on the stage. 287 00:15:15,290 --> 00:15:18,260 And just by adding this one block, When This Sprite Clicked, 288 00:15:18,260 --> 00:15:21,650 we were able to add functionality-- some behavior that happens, 289 00:15:21,650 --> 00:15:26,030 some functions that run when we click on a particular sprite. 290 00:15:26,030 --> 00:15:29,150 But clicking isn't the only way that users can interact with a project, 291 00:15:29,150 --> 00:15:31,790 they might also, for example, type something 292 00:15:31,790 --> 00:15:35,552 onto the keyboard-- press a key, for example, and that too is an Event. 293 00:15:35,552 --> 00:15:37,760 We've seen a couple of different types of Events now, 294 00:15:37,760 --> 00:15:41,060 but pressing a key on the keyboard is absolutely an Event too 295 00:15:41,060 --> 00:15:44,640 that we might want our Scratch projects to be able to respond to. 296 00:15:44,640 --> 00:15:45,960 So let's give that a try-- 297 00:15:45,960 --> 00:15:52,640 I'll get rid of our drums for now, and let's add a fish. 298 00:15:52,640 --> 00:16:00,200 We'll go back to the fish and we'll bring the fish into our project, 299 00:16:00,200 --> 00:16:03,768 and I would like for the fish to do something when I press a key. 300 00:16:03,768 --> 00:16:06,560 So let's start simple-- let's first figure out what Event do I need 301 00:16:06,560 --> 00:16:07,670 to use-- 302 00:16:07,670 --> 00:16:12,020 and well we have this block here that is When Space Key Pressed. 303 00:16:12,020 --> 00:16:15,440 Which I guess would mean that, when I press the space bar on my keyboard, 304 00:16:15,440 --> 00:16:17,210 something's going to happen. 305 00:16:17,210 --> 00:16:18,540 What do I want to have happen? 306 00:16:18,540 --> 00:16:25,440 Well, let's go into sound, and let's Play the Sound Bubbles Until Done. 307 00:16:25,440 --> 00:16:28,535 And so now, I'll go ahead and press the Space key-- 308 00:16:28,535 --> 00:16:33,090 309 00:16:33,090 --> 00:16:36,090 and when I press Space key, you hear the bubbles-- and every time 310 00:16:36,090 --> 00:16:38,100 I press this Space key, that's a different Event 311 00:16:38,100 --> 00:16:41,310 and that's going to trigger the running of that code. 312 00:16:41,310 --> 00:16:44,930 313 00:16:44,930 --> 00:16:48,490 But notice too that this block is actually customizable-- 314 00:16:48,490 --> 00:16:51,010 I can change it, parameterize it slightly, 315 00:16:51,010 --> 00:16:52,960 just by clicking on this arrow. 316 00:16:52,960 --> 00:16:55,420 And this opens up a menu where I can choose 317 00:16:55,420 --> 00:16:58,090 what key it's going to respond to-- it doesn't just 318 00:16:58,090 --> 00:17:01,130 have to be when the Space bar on my keyboard is pressed. 319 00:17:01,130 --> 00:17:05,410 I can have it respond to, let's say, the Right arrow or the Left arrow. 320 00:17:05,410 --> 00:17:08,150 So I go to Right arrow, and instead of playing 321 00:17:08,150 --> 00:17:10,710 a sound, when you get the right arrow-- 322 00:17:10,710 --> 00:17:14,990 let's go ahead and change the x value by 10. 323 00:17:14,990 --> 00:17:18,020 Remember that each sprite exists in this xy 324 00:17:18,020 --> 00:17:21,710 coordinate grid on the stage, where x refers to how far to the left 325 00:17:21,710 --> 00:17:25,099 or to the right a particular sprite is-- and y refers to how 326 00:17:25,099 --> 00:17:27,770 far up or down a particular sprite is. 327 00:17:27,770 --> 00:17:32,540 And so now, the Right arrow key is going to move the fish to the right 328 00:17:32,540 --> 00:17:33,660 by 10 spaces. 329 00:17:33,660 --> 00:17:35,670 So I'll press the Right arrow key and you'll 330 00:17:35,670 --> 00:17:37,670 see the fish move a little bit-- press it again, 331 00:17:37,670 --> 00:17:43,530 and it moves, and it keeps moving every time I press that key. 332 00:17:43,530 --> 00:17:47,007 Let's now add the ability for this Right to respond to the Left arrow key. 333 00:17:47,007 --> 00:17:48,840 And this is going to be very similar, I just 334 00:17:48,840 --> 00:17:50,520 want to move in the opposite direction-- 335 00:17:50,520 --> 00:17:52,800 I want to go left instead of going right. 336 00:17:52,800 --> 00:17:56,910 And I could drag the event out and then drag another change x by and change it 337 00:17:56,910 --> 00:17:59,117 to negative 10 instead of 10 this time. 338 00:17:59,117 --> 00:18:01,950 But in this case, because it's very similar to the code I've already 339 00:18:01,950 --> 00:18:06,330 written, I can actually Control-click or Right-click on this script 340 00:18:06,330 --> 00:18:08,580 and just say Duplicate. 341 00:18:08,580 --> 00:18:13,660 And when I Duplicate, I get a copy of what it is that I've just written 342 00:18:13,660 --> 00:18:14,730 and now I can modify it. 343 00:18:14,730 --> 00:18:17,320 Instead of responding to the Right arrow, 344 00:18:17,320 --> 00:18:20,010 let's have this script respond to the Left arrow. 345 00:18:20,010 --> 00:18:24,300 And instead of changing x by 10, let's change x by negative 10 346 00:18:24,300 --> 00:18:27,660 to have the fish move in the negative direction instead. 347 00:18:27,660 --> 00:18:30,870 And just for fun, let's go ahead and click on the stage 348 00:18:30,870 --> 00:18:34,590 and change the backdrop to underwater so that it actually feels like the fish is 349 00:18:34,590 --> 00:18:37,682 swimming around underwater. 350 00:18:37,682 --> 00:18:39,640 And so now when I press the Right arrow, you'll 351 00:18:39,640 --> 00:18:43,600 see the fish moving to the right, and when I press the Left arrow, 352 00:18:43,600 --> 00:18:46,240 the fish is moving backwards? 353 00:18:46,240 --> 00:18:49,750 That may not be exactly what I want, but it is moving to the left at least. 354 00:18:49,750 --> 00:18:51,580 And I can make this a little better maybe 355 00:18:51,580 --> 00:18:53,697 by allowing its rotation to change-- 356 00:18:53,697 --> 00:18:55,780 let it face the left when it's moving to the left, 357 00:18:55,780 --> 00:18:58,300 let it face the right when it's moving to the right. 358 00:18:58,300 --> 00:19:02,540 And remember I can do that just by using this Point In Direction block. 359 00:19:02,540 --> 00:19:05,020 So when the Right arrow is pressed, let's go ahead 360 00:19:05,020 --> 00:19:08,740 and Point In Direction 90 degrees, meaning facing the right, 361 00:19:08,740 --> 00:19:10,490 and move 10 steps. 362 00:19:10,490 --> 00:19:14,923 And if the Left arrow key is pressed, let's Point In Direction negative 90. 363 00:19:14,923 --> 00:19:16,840 And if you didn't remember what number it was, 364 00:19:16,840 --> 00:19:20,330 you could use this dial of course to change the value as well 365 00:19:20,330 --> 00:19:22,720 and then change x by negative 10. 366 00:19:22,720 --> 00:19:25,000 And this might be closer, let's try it out-- 367 00:19:25,000 --> 00:19:28,360 I press Right and the fish moves to the right. 368 00:19:28,360 --> 00:19:32,580 Now I press the Left arrow key and the fish turns upside down-- 369 00:19:32,580 --> 00:19:34,090 OK, not quite what I wanted. 370 00:19:34,090 --> 00:19:36,820 Again, by default-- when you rotate a sprite, 371 00:19:36,820 --> 00:19:38,540 it's just going to rotate in a circle-- 372 00:19:38,540 --> 00:19:40,300 which means it might end up upside down. 373 00:19:40,300 --> 00:19:43,480 If you just want it to be able to go back and forth between left and right, 374 00:19:43,480 --> 00:19:48,190 be sure to go to Direction and change the fish's rotation style 375 00:19:48,190 --> 00:19:49,750 to left and right. 376 00:19:49,750 --> 00:19:53,950 And now, when it goes right, it faces the right, and when it goes left, 377 00:19:53,950 --> 00:19:56,120 it faces the left. 378 00:19:56,120 --> 00:19:58,640 Notice too that, if you wanted to change this with code, 379 00:19:58,640 --> 00:20:00,080 you also have this block here-- 380 00:20:00,080 --> 00:20:03,380 Set Rotation Style-- that will let you using a block of code 381 00:20:03,380 --> 00:20:08,370 decide what rotation style that particular sprite should have. 382 00:20:08,370 --> 00:20:12,843 And so now I have the ability to let this fish move left and right-- 383 00:20:12,843 --> 00:20:14,010 and I could add to this too. 384 00:20:14,010 --> 00:20:18,030 If I want to let it move up and down, then I'll add one more Event, and say-- 385 00:20:18,030 --> 00:20:21,570 not when the Space key is pressed, but when the Up arrow is pressed. 386 00:20:21,570 --> 00:20:23,520 Let's go ahead and have it move-- 387 00:20:23,520 --> 00:20:25,470 we're not changing x anymore, we're instead 388 00:20:25,470 --> 00:20:31,020 changing y because y refers to the up and down direction of the sprite. 389 00:20:31,020 --> 00:20:35,010 So when the Up arrow key is pressed, we're going to change y by 10, 390 00:20:35,010 --> 00:20:37,620 and I'll duplicate this by going to the Event block 391 00:20:37,620 --> 00:20:41,740 Control- or Right-clicking, clicking Duplicate. 392 00:20:41,740 --> 00:20:48,310 And now, when the Down arrow is pressed, let's change y by negative 10. 393 00:20:48,310 --> 00:20:51,060 And so now I can get my fish to move to the right, 394 00:20:51,060 --> 00:20:56,050 I can get my fish to move to the left, I can get it to move up or down as well. 395 00:20:56,050 --> 00:20:58,560 And I can get it to move across the stage all just 396 00:20:58,560 --> 00:21:00,930 by pressing keys on the keyboard. 397 00:21:00,930 --> 00:21:02,682 And using that ability, you could imagine 398 00:21:02,682 --> 00:21:04,140 trying to create some sort of game. 399 00:21:04,140 --> 00:21:06,600 Maybe you've played a game on a computer before where 400 00:21:06,600 --> 00:21:08,790 you use the arrow keys or other keys on the keyboard 401 00:21:08,790 --> 00:21:10,590 to move some character around. 402 00:21:10,590 --> 00:21:14,190 Now we have that exact same ability within Scratch itself too. 403 00:21:14,190 --> 00:21:17,350 By clicking and by pressing various different keys on the keyboard, 404 00:21:17,350 --> 00:21:21,250 we can get our sprite to respond to that as well. 405 00:21:21,250 --> 00:21:23,400 And it's not just the Space and the arrow keys-- 406 00:21:23,400 --> 00:21:25,980 it's letters of the alphabet that you could have be pressed, 407 00:21:25,980 --> 00:21:29,250 or numbers on the keypad for example that might be pressed. 408 00:21:29,250 --> 00:21:31,460 And so let's give that a try too just for fun-- 409 00:21:31,460 --> 00:21:33,270 I'll add a few more blocks here. 410 00:21:33,270 --> 00:21:35,730 Let's let the fish change in size-- 411 00:21:35,730 --> 00:21:39,330 maybe I want to be able to choose between how big or small the fish is 412 00:21:39,330 --> 00:21:40,600 going to be. 413 00:21:40,600 --> 00:21:44,610 And so when the 1 key is pressed-- 414 00:21:44,610 --> 00:21:46,200 let's make it small when you press 1. 415 00:21:46,200 --> 00:21:53,150 So we'll go into Looks and let's set the size to maybe 50%. 416 00:21:53,150 --> 00:21:55,940 And I'll duplicate this block again by clicking, 417 00:21:55,940 --> 00:22:00,220 or Right-clicking or Control-clicking on the Event block, clicking Duplicate. 418 00:22:00,220 --> 00:22:04,870 Now when the 2 key is pressed, let's make it normal size 100, 419 00:22:04,870 --> 00:22:06,670 and we'll duplicate one more time. 420 00:22:06,670 --> 00:22:09,310 Now, when the 3 key is pressed-- 421 00:22:09,310 --> 00:22:13,220 let's add the size to be bigger, we'll set it to be 200%. 422 00:22:13,220 --> 00:22:15,230 And so now, watch what happens-- 423 00:22:15,230 --> 00:22:21,370 I can still move the fish around, it's still responding to the arrow keys, 424 00:22:21,370 --> 00:22:23,578 but now I can also use the numbers to control how 425 00:22:23,578 --> 00:22:25,120 big or small the fish is going to be. 426 00:22:25,120 --> 00:22:29,680 If I press 1, the fish shrinks-- it's now 50% of the usual size. 427 00:22:29,680 --> 00:22:32,680 When I press 2, it goes back to normal size-- 428 00:22:32,680 --> 00:22:36,100 and when I press 3, the fish gets much larger-- 429 00:22:36,100 --> 00:22:39,790 it goes to 200% of its original size. 430 00:22:39,790 --> 00:22:43,210 And so by putting together these various different scripts, each of which 431 00:22:43,210 --> 00:22:45,980 is responding to a different key on the keyboard, 432 00:22:45,980 --> 00:22:49,630 you can allow the user to control your sprites in any number of ways. 433 00:22:49,630 --> 00:22:53,290 Allowing them to interact with the stage by telling them what to click on, 434 00:22:53,290 --> 00:22:57,340 what to press, in order to see a particular response appear on the stage 435 00:22:57,340 --> 00:22:58,913 as well. 436 00:22:58,913 --> 00:23:01,330 And so now we have the ability within our Scratch programs 437 00:23:01,330 --> 00:23:04,570 to respond to a number of Events that can respond to the flag Being Clicked, 438 00:23:04,570 --> 00:23:09,460 to a click of something on the stage, also responding to a press of a key. 439 00:23:09,460 --> 00:23:12,040 But there are a couple of other fun Events 440 00:23:12,040 --> 00:23:15,520 that we might let our sprites respond to, so let's try one of them now. 441 00:23:15,520 --> 00:23:18,860 I'll go ahead and get rid of the fish, and let's 442 00:23:18,860 --> 00:23:23,060 change the backdrop-- we'll go back to the plain white backdrop, 443 00:23:23,060 --> 00:23:25,178 and let's add a new sprite. 444 00:23:25,178 --> 00:23:28,220 And the sprite I want to add this time is the balloon-- we haven't really 445 00:23:28,220 --> 00:23:29,380 played around with that. 446 00:23:29,380 --> 00:23:33,300 I'll go ahead and center the balloon and I'll go into Events, 447 00:23:33,300 --> 00:23:36,720 and the Event I'm curious about now is this one here-- 448 00:23:36,720 --> 00:23:39,870 When Loudness Is Greater Than 10-- 449 00:23:39,870 --> 00:23:43,920 and loudness refers to input coming in from your computer's microphone. 450 00:23:43,920 --> 00:23:45,930 So when you use this block for the first time, 451 00:23:45,930 --> 00:23:47,820 your browser might ask you for permission 452 00:23:47,820 --> 00:23:49,778 to use your microphone because Scratch is going 453 00:23:49,778 --> 00:23:51,760 to be listening to that microphone. 454 00:23:51,760 --> 00:23:54,990 And what it's going to be doing is calculating how loudly 455 00:23:54,990 --> 00:23:56,580 it hears something, for example-- 456 00:23:56,580 --> 00:23:59,010 it's all going to be on a 0 to 100 scale where 457 00:23:59,010 --> 00:24:03,240 0 is like complete silence and 100 is very, very loud. 458 00:24:03,240 --> 00:24:09,000 And so if I set this to maybe 30 or so, then this code is going to respond, 459 00:24:09,000 --> 00:24:14,410 and it's going to run some code whenever the loudness gets above 30 for example. 460 00:24:14,410 --> 00:24:18,480 And what I'm going to do is, when the loudness gets above 30, 461 00:24:18,480 --> 00:24:22,380 let's go to Looks and change the size by 10. 462 00:24:22,380 --> 00:24:25,077 We're going to increase the size of the balloon by 10-- 463 00:24:25,077 --> 00:24:28,410 and I haven't connected them yet because I don't want this code to start running 464 00:24:28,410 --> 00:24:32,640 just yet-- but once I connect it, what's going to happen is that whenever 465 00:24:32,640 --> 00:24:35,235 Scratch detects that the loudness has gone above 30-- 466 00:24:35,235 --> 00:24:37,860 and I might have to play around with that number a little bit-- 467 00:24:37,860 --> 00:24:40,653 then the size of the balloon is going to change by 10. 468 00:24:40,653 --> 00:24:42,570 And so this lets me have a little bit of fun-- 469 00:24:42,570 --> 00:24:44,820 I can try and blow up the balloon, for example. 470 00:24:44,820 --> 00:24:54,950 I'll connect these two blocks and every time I blow, 471 00:24:54,950 --> 00:24:57,860 that triggers the loudness threshold-- it goes above the 30-- 472 00:24:57,860 --> 00:25:00,260 and I've disconnected it for now so that the balloon doesn't get bigger 473 00:25:00,260 --> 00:25:01,885 and bigger while I'm talking right now. 474 00:25:01,885 --> 00:25:04,850 But every time the loudness goes above a particular threshold, 475 00:25:04,850 --> 00:25:07,130 well then the size of the balloon is going to change-- 476 00:25:07,130 --> 00:25:10,160 and you probably saw that balloon get a little bit bigger and bigger 477 00:25:10,160 --> 00:25:10,730 every time. 478 00:25:10,730 --> 00:25:13,813 And you can have fun with this playing around with that threshold deciding 479 00:25:13,813 --> 00:25:17,000 how loud something needs to be, or how quiet something needs to be in order 480 00:25:17,000 --> 00:25:19,680 to get a particular result to happen. 481 00:25:19,680 --> 00:25:24,170 And so loudness is another type of Event that Scratch will let you respond to. 482 00:25:24,170 --> 00:25:27,980 And just for one final example, notice here too that this loudness is 483 00:25:27,980 --> 00:25:31,640 a dropdown menu-- in the same way that pressing a key on the keyboard had 484 00:25:31,640 --> 00:25:33,290 a dropdown menu where I could say-- 485 00:25:33,290 --> 00:25:35,480 I don't just want the Scratch project to respond 486 00:25:35,480 --> 00:25:37,430 to when the space key is pressed, but I want 487 00:25:37,430 --> 00:25:40,310 it to respond to an arrow key, or a letter, or a number. 488 00:25:40,310 --> 00:25:42,620 I have another option here-- 489 00:25:42,620 --> 00:25:45,440 I can choose when loudness is greater than 30, 490 00:25:45,440 --> 00:25:48,590 or when Timer is greater than a particular number. 491 00:25:48,590 --> 00:25:51,530 And so every Scratch project, though we haven't seen it just yet, 492 00:25:51,530 --> 00:25:54,410 has a built-in timer and the timer is keeping 493 00:25:54,410 --> 00:25:58,832 track of how much time has passed since we started the project. 494 00:25:58,832 --> 00:26:01,790 So when the project starts, we start counting how much time has passed, 495 00:26:01,790 --> 00:26:04,680 and that timer is keeping track of that for us. 496 00:26:04,680 --> 00:26:07,460 And so originally, if you think back to our first program 497 00:26:07,460 --> 00:26:10,370 that we made earlier, where we had the cat and the dinosaur talking 498 00:26:10,370 --> 00:26:13,190 to each other and they both said hello at the same time, 499 00:26:13,190 --> 00:26:15,450 why did they both say hello at the same time? 500 00:26:15,450 --> 00:26:18,350 They both said hello at the same time because they 501 00:26:18,350 --> 00:26:21,260 were both responding to the same event, the When Flag 502 00:26:21,260 --> 00:26:23,000 Clicked Event that happened once. 503 00:26:23,000 --> 00:26:27,440 And as soon as I pressed the green flag, then both the cat and the dinosaur 504 00:26:27,440 --> 00:26:28,392 said hello. 505 00:26:28,392 --> 00:26:31,100 In an actual conversation, of course, they probably wouldn't both 506 00:26:31,100 --> 00:26:32,570 say hello at the same time-- 507 00:26:32,570 --> 00:26:37,310 the cat might say hello and the dinosaur might respond a few seconds later. 508 00:26:37,310 --> 00:26:39,650 And we can take advantage now of this Timer-- 509 00:26:39,650 --> 00:26:43,410 the ability to wait for the Timer to reach a particular number. 510 00:26:43,410 --> 00:26:46,820 And when the Timer reaches that number, then an Event 511 00:26:46,820 --> 00:26:51,660 is triggered-- that will let us time sprites a little bit more precisely. 512 00:26:51,660 --> 00:26:53,660 And so let's give that a try by going back 513 00:26:53,660 --> 00:26:56,690 to the project we created at the beginning of today. 514 00:26:56,690 --> 00:27:02,420 I'll delete the balloon, go into my sprites, and let's add our cat back-- 515 00:27:02,420 --> 00:27:04,490 we'll bring our cat over to the left. 516 00:27:04,490 --> 00:27:07,130 And I'll add one more sprite, I'll go ahead 517 00:27:07,130 --> 00:27:10,070 and bring our dinosaur back as well-- 518 00:27:10,070 --> 00:27:13,022 that dinosaur is going to have a rotation style of left right 519 00:27:13,022 --> 00:27:15,230 because I only want it to face the left or the right. 520 00:27:15,230 --> 00:27:18,690 And I'll change the direction to negative 90 521 00:27:18,690 --> 00:27:22,240 so that the cat and the dinosaur are facing each other. 522 00:27:22,240 --> 00:27:24,610 And for the cat, the code is going to be the same-- 523 00:27:24,610 --> 00:27:29,410 we'll have the cat respond to an Event, the Event will be When Flag Is Clicked, 524 00:27:29,410 --> 00:27:33,870 I want the cat to say hello for two seconds. 525 00:27:33,870 --> 00:27:36,330 But I want the dinosaur not to immediately say hello 526 00:27:36,330 --> 00:27:39,720 when the flag is clicked, but to wait for the cat-- let the cat say hello 527 00:27:39,720 --> 00:27:42,420 and then the dinosaur can respond. 528 00:27:42,420 --> 00:27:44,650 So under the dinosaur, instead of using the 529 00:27:44,650 --> 00:27:48,150 When Flag Clicked Event which would happen right away, 530 00:27:48,150 --> 00:27:55,150 I'm instead going to use them When Timer Is Greater Than 2. 531 00:27:55,150 --> 00:27:57,350 In other words, after the Timer reaches 2, 532 00:27:57,350 --> 00:28:00,910 in other words, after two seconds have passed in my project-- 533 00:28:00,910 --> 00:28:06,730 we'll then and only then should the dinosaur say hello for two seconds 534 00:28:06,730 --> 00:28:07,827 as well. 535 00:28:07,827 --> 00:28:09,160 And so now notice what happens-- 536 00:28:09,160 --> 00:28:15,890 I'll press the green flag, the cat says "hello" for two seconds, 537 00:28:15,890 --> 00:28:20,248 and only once the cat is done the dinosaur then says "hello" as well. 538 00:28:20,248 --> 00:28:22,040 And that's because the dinosaur is waiting, 539 00:28:22,040 --> 00:28:25,370 it's not going right when the project starts, it's waiting for the Timer 540 00:28:25,370 --> 00:28:26,300 to reach 2. 541 00:28:26,300 --> 00:28:30,530 And the Timer, again, begins every time we click on the green flag-- 542 00:28:30,530 --> 00:28:33,200 but when the green flag is clicked, the Timer resets back to 0, 543 00:28:33,200 --> 00:28:36,770 and it's counting up in terms of how many seconds have passed 544 00:28:36,770 --> 00:28:39,530 since the beginning of the project. 545 00:28:39,530 --> 00:28:42,773 And there are other events that we can use inside of Scratch as well that we 546 00:28:42,773 --> 00:28:43,940 haven't yet taken a look at. 547 00:28:43,940 --> 00:28:47,450 There's one here, for example, that checks when the backdrop switches 548 00:28:47,450 --> 00:28:48,800 to a particular backdrop. 549 00:28:48,800 --> 00:28:52,010 So recall before we had those various different backdrops with the Arctic, 550 00:28:52,010 --> 00:28:53,540 and the jungle, and underwater? 551 00:28:53,540 --> 00:28:57,770 You could add Events that say, as soon as the backdrop switches to underwater, 552 00:28:57,770 --> 00:29:00,480 then play those bubbles or the ocean sounds for example, 553 00:29:00,480 --> 00:29:02,810 or do some other action depending on what 554 00:29:02,810 --> 00:29:04,520 backdrop happens to be switched to. 555 00:29:04,520 --> 00:29:07,670 But you can hopefully now start to see how these events really 556 00:29:07,670 --> 00:29:10,970 start to make our Scratch projects more powerful and more interactive. 557 00:29:10,970 --> 00:29:14,990 We no longer need to say, run this block of code now, run that block of code 558 00:29:14,990 --> 00:29:15,500 now-- 559 00:29:15,500 --> 00:29:18,590 we can add Events to our project and let our project 560 00:29:18,590 --> 00:29:20,300 decide when to run that code. 561 00:29:20,300 --> 00:29:24,320 Letting it respond to when the project begins, or when we click on something, 562 00:29:24,320 --> 00:29:27,830 or when we press a key on the keyboard, or when the loudness changes, 563 00:29:27,830 --> 00:29:30,050 or any number of other different types of events 564 00:29:30,050 --> 00:29:32,630 that Scratch now gives us the ability to use. 565 00:29:32,630 --> 00:29:36,230 And hopefully now using Events, we'll be able to create all the more interesting 566 00:29:36,230 --> 00:29:38,297 and interactive projects as well. 567 00:29:38,297 --> 00:29:41,130 That's it for An Introduction to Programming with Scratch for today. 568 00:29:41,130 --> 00:29:44,210 Next time, we'll take these ideas and build up on them even more, 569 00:29:44,210 --> 00:29:46,000 see you then. 570 00:29:46,000 --> 00:29:47,000