WEBVTT

00:00.000 --> 00:23.040
Alright, we are back, and I hope you did that little exercise, because it was very simple.

00:23.040 --> 00:26.520
You just needed to replicate it to the other colored buttons.

00:26.520 --> 00:28.160
So here's what I'm going to do.

00:28.240 --> 00:31.360
First, I'm going to solve this little exercise.

00:31.360 --> 00:37.440
So I'm going to go to the red button, and I'm going to drag this code to, for example, the orange sprite.

00:37.440 --> 00:40.960
This will duplicate the code inside the orange sprite as well.

00:40.960 --> 00:44.800
So I'm going to release the mouse, and I'm going to go to the orange sprite,

00:44.800 --> 00:48.640
and notice that this code was duplicated inside the sprite as well.

00:48.640 --> 00:53.280
Now, instead of broadcasting red for orange, I'm going to broadcast a new message.

00:53.280 --> 00:56.160
So in the drop down, I'm going to select a new message.

00:56.160 --> 00:59.040
I'm going to name this orange.

00:59.040 --> 01:03.040
Now, I'm going to go to pencil, and I'm going to right-click on the small piece of code,

01:03.040 --> 01:05.840
and I'm going to click duplicate.

01:05.840 --> 01:11.680
So when I receive, in this case, orange, I'm going to set the pink color to the appropriate orange color.

01:11.680 --> 01:17.200
So I'm going to hit the eyedropper, and I'm going to select that orange color in the button.

01:17.200 --> 01:20.960
And I'm going to do the same for all the other colored sprites now.

01:21.040 --> 01:22.720
So I'm going to fast forward a little bit.

01:26.640 --> 01:31.040
All right, so I have every single button sending a new message when it's clicked.

01:31.040 --> 01:33.440
Now, I'm going to make the pencil receive those messages,

01:33.440 --> 01:35.680
and set the pen to the appropriate color.

01:35.680 --> 01:37.280
Again, a little fast forward.

01:42.880 --> 01:44.880
Okay, all right.

01:44.880 --> 01:48.480
So we have small scripts here for every single color for the pencil.

01:48.480 --> 01:52.720
When any one of these colored buttons is clicked, they will broadcast a different message,

01:52.720 --> 01:57.440
and the pencil will react to every single one of those messages by setting its pink color to a

01:57.440 --> 02:02.560
different color. Let's test it out. So if I stop and start the application again,

02:02.560 --> 02:05.920
the pencil starts with black. But let's change the colors.

02:06.720 --> 02:16.480
So red, orange, yellow, green, blue, indigo, and violet.

02:17.200 --> 02:19.040
So all the colors are working properly.

02:19.840 --> 02:22.080
Now let's focus on the buttons on the second layer.

02:22.640 --> 02:26.240
Now we're going to program those, and I'm going to start with the magic wand,

02:26.240 --> 02:28.800
whose purpose is to erase what we've drawn on the stage.

02:29.360 --> 02:34.320
Now, you might think that erasing colors selectively here on the stage might be complicated,

02:34.320 --> 02:38.160
but it's actually not. It's basically drawing white on the stage.

02:38.720 --> 02:41.520
It's the same as erasing, because the background is white.

02:42.160 --> 02:47.200
So the user of this application will not be able to tell if we're erasing the color

02:47.200 --> 02:52.000
or just drawing white on top of it. So we're just going to use this dirty little trick.

02:52.880 --> 02:56.640
All right, so when we click on the magic wand, the erase button,

02:56.640 --> 03:01.200
we're just going to broadcast a message to the pencil to switch the costume to the magic wand

03:01.200 --> 03:05.600
and just draw white on top of it. That is set its pencil color to white,

03:05.600 --> 03:08.000
so I'm going to go to events when the sprite is clicked.

03:08.000 --> 03:14.080
I'm going to zoom this in a little bit, so when the sprite is clicked,

03:14.080 --> 03:18.240
I'm going to broadcast a new message. So I'm going to broadcast a new message.

03:18.240 --> 03:19.920
I'm going to call this magic wand.

03:21.280 --> 03:25.360
Okay, and pencil the pencil sprite. When it receives the magic wand,

03:25.360 --> 03:28.480
it will change its costume and set the pink color to white.

03:28.480 --> 03:30.800
So when I receive the magic wand message,

03:32.320 --> 03:34.320
I'm going to set the pink color to white,

03:34.320 --> 03:36.400
so I'm just going to right click and duplicate it.

03:37.040 --> 03:39.520
Or you might want to drag it from the pen section here

03:39.520 --> 03:42.160
and then click inside the set pen color to

03:42.160 --> 03:45.600
and drag the second slider all the way to the left and the third slider

03:45.600 --> 03:47.760
all the way to the right to make the color complete.

03:48.480 --> 03:53.840
Only white. Okay, then go to the look section and make the pencil sprite.

03:54.960 --> 03:56.800
Switch its costume to magic wand.

03:57.520 --> 04:00.400
Okay, so if I start the application again,

04:00.400 --> 04:02.240
I can draw something on the screen.

04:02.240 --> 04:04.080
And if I hit the magic one button,

04:04.160 --> 04:06.080
notice that it changed its costume.

04:06.080 --> 04:07.680
And if I draw on top of it,

04:07.680 --> 04:09.440
notice that it starts erasing stuff.

04:10.320 --> 04:13.920
Now let's implement a similar mechanism for the pencil button over here.

04:15.120 --> 04:17.040
So I'm going to click on the draw button

04:18.240 --> 04:19.520
and I'm going to go to events.

04:21.040 --> 04:22.240
And when the sprite is clicked,

04:23.280 --> 04:25.040
I'm going to broadcast a new message

04:26.160 --> 04:27.440
that I'm going to name pencil

04:29.120 --> 04:30.160
and the pencil sprite.

04:30.880 --> 04:32.400
When it receives the pencil message,

04:33.200 --> 04:35.120
it will set its pen color to black

04:35.120 --> 04:37.040
and switch its costume back to the pencil.

04:37.760 --> 04:39.840
So I'm just going to duplicate this little script.

04:40.800 --> 04:43.200
So when I receive the pencil message,

04:44.080 --> 04:46.000
I'm going to set the pink color to

04:46.000 --> 04:48.640
and I'm going to drag the third slider all the way to the left

04:48.640 --> 04:50.400
until the color becomes black.

04:50.400 --> 04:53.040
Okay, and then switch its costume to pencil.

04:53.600 --> 04:56.480
All right, so let's play around with the application a little bit.

04:57.040 --> 04:58.320
So right from the start,

04:58.320 --> 05:01.440
I have something to fix because the default costume for my pen

05:01.440 --> 05:02.560
is not the pen.

05:02.560 --> 05:04.000
It's the magic wand.

05:04.000 --> 05:05.360
And if I start drawing,

05:05.360 --> 05:07.200
we have the magic wand costume,

05:07.200 --> 05:08.800
yet we're still drawing on the stitch.

05:09.440 --> 05:10.480
This is wrong.

05:10.480 --> 05:12.560
So I'm going to stop the application

05:12.560 --> 05:13.840
and right at the beginning,

05:13.840 --> 05:15.120
when the flag is clicked,

05:15.120 --> 05:17.280
I'm going to set the costume to pencil.

05:17.280 --> 05:18.720
So I'm going to go to looks

05:18.720 --> 05:21.040
and I'm going to switch the costume to pencil.

05:21.040 --> 05:22.720
So if I start this again,

05:22.720 --> 05:24.720
notice that the costume went back to pencil.

05:25.280 --> 05:26.720
So if I hit the magic wand,

05:27.520 --> 05:28.480
it's able to delete.

05:29.440 --> 05:30.960
And if I hit one of the colors,

05:32.960 --> 05:34.080
well, this is wrong

05:34.080 --> 05:36.560
because we still have the magic wand costume,

05:36.560 --> 05:38.160
yet we can draw in different color.

05:38.720 --> 05:40.240
So this is again wrong.

05:40.800 --> 05:44.480
We need to fix the pencil sprite to switch its costume back to pencil,

05:44.480 --> 05:46.240
when we click either of the colorid buttons.

05:48.080 --> 05:50.080
So I'm going to switch costume to pencil B,

05:50.800 --> 05:53.600
when I receive any one of the colorid messages red,

05:53.600 --> 05:55.920
orange, blue, and so on and so forth.

05:56.720 --> 05:58.720
So I'm going to add the purple code block

05:58.720 --> 06:00.480
in every single one of the receive scripts.

06:01.840 --> 06:03.280
So I fast forward a little bit.

06:05.280 --> 06:06.640
If I'm going too fast,

06:06.640 --> 06:08.080
feel free to pause the video

06:09.600 --> 06:10.720
and add the purple block

06:10.720 --> 06:12.880
to every single one of your colored receive scripts.

06:13.600 --> 06:14.400
All right.

06:14.400 --> 06:16.560
But right now, I'm going to test the application

06:18.960 --> 06:20.880
and notice that when I have the magic wand

06:20.880 --> 06:22.400
and switch back to a colored block,

06:23.440 --> 06:25.440
the costume is switched back to pencil

06:25.440 --> 06:26.880
and the color is the correct one.

06:28.000 --> 06:28.800
All right.

06:28.800 --> 06:30.720
So we have three more buttons to go,

06:30.720 --> 06:33.600
which fortunately are going to be pretty easy to program.

06:33.600 --> 06:35.680
Let me click, for example, on the grow button.

06:36.320 --> 06:38.320
So when the grow button is clicked,

06:38.320 --> 06:40.720
we'll need to tell the pencil to increase its pen size.

06:41.280 --> 06:43.680
Now you're already familiar with sending messages,

06:43.680 --> 06:45.840
so that means broadcasting a new message,

06:45.840 --> 06:48.320
but the pencil will react and increase its pen size.

06:48.800 --> 06:50.400
So I'm going to go to events,

06:50.400 --> 06:51.600
and when this spread is clicked,

06:53.040 --> 06:54.800
I'm going to broadcast another message,

06:56.240 --> 06:58.160
and I'm going to name this grow pen size.

07:00.320 --> 07:03.200
Okay, and the pencil sprite will react to that

07:04.080 --> 07:06.960
by saying when I receive grow pen size,

07:08.800 --> 07:10.400
I'm going to go to the pen section

07:10.400 --> 07:13.200
and I'm going to add the screen change pen size by one.

07:13.840 --> 07:15.280
This is exactly what I want,

07:15.840 --> 07:17.120
and in a similar fashion,

07:17.120 --> 07:19.040
the shrink button will act in the same way.

07:21.280 --> 07:22.640
So when this sprite is clicked,

07:23.360 --> 07:26.160
I'm going to broadcast a new message,

07:26.160 --> 07:28.000
and I'm going to name this shrink pen size.

07:30.240 --> 07:33.120
All right, and we'll make the pencil react to that,

07:33.120 --> 07:35.920
and I'm simply going to duplicate this last script that I wrote.

07:37.920 --> 07:39.680
And instead of group and size,

07:39.680 --> 07:41.840
I'm going to select shrink based size.

07:42.400 --> 07:44.640
Instead of changing pen size by one,

07:44.640 --> 07:46.640
I'm going to change it by negative one,

07:46.640 --> 07:49.040
which means I'm decreasing the pen size.

07:49.040 --> 07:50.640
So let me test this out,

07:50.640 --> 07:53.840
so I'm going to stop the application and start it again.

07:53.840 --> 07:56.240
And I'm going to draw a few things on the screen.

07:56.240 --> 07:58.160
I'm going to select a different color,

07:58.160 --> 08:00.880
and I'm going to click this groove button a bunch of times.

08:00.880 --> 08:03.040
So 1, 2, 3, 4.

08:03.680 --> 08:05.360
Notice that when I draw again,

08:05.360 --> 08:07.040
the line is so much thicker,

08:07.040 --> 08:09.360
which means that the messages had the desired effect.

08:10.000 --> 08:11.440
Let me click on another color

08:11.440 --> 08:13.920
and click the shrink button size a bunch of times,

08:13.920 --> 08:16.400
and notice that the pen size is so much thinner now.

08:17.120 --> 08:17.920
Cool.

08:18.000 --> 08:20.640
So we have four out of five buttons working nicely.

08:21.120 --> 08:24.320
The last button is the easiest of all this erase all button.

08:24.880 --> 08:26.480
So when this button is clicked,

08:26.480 --> 08:29.360
we want every single mark on the screen erased,

08:29.360 --> 08:30.880
and this is very, very easy.

08:33.200 --> 08:34.320
When the sprite is clicked,

08:35.760 --> 08:38.400
we want the pen to erase all the marks on the screen,

08:38.400 --> 08:39.120
and that is it.

08:40.160 --> 08:42.400
So if I stop and start the application again,

08:43.440 --> 08:45.600
and if I draw a bunch of things on different colors,

08:46.560 --> 08:48.400
and if I hit this button,

08:48.400 --> 08:49.760
everything will go away, ma'am.

08:50.400 --> 08:51.600
And at this moment,

08:51.600 --> 08:53.200
I am glad to see that we are done.

08:53.760 --> 08:56.400
We have a fully functional paint and draw application

08:56.400 --> 08:58.320
that you created from Absolute Scratch.

08:58.880 --> 09:01.440
And I'm very proud of you and what you've learned here.

09:02.000 --> 09:04.080
So you created your own sprites.

09:04.080 --> 09:05.360
You'll learn about the pen tool.

09:05.840 --> 09:08.720
You made it follow your mouse with just a tiny little script.

09:09.360 --> 09:10.720
And very importantly,

09:10.720 --> 09:12.640
you've learned that sprites can broadcast

09:12.640 --> 09:14.320
and can receive messages

09:14.400 --> 09:16.000
and be programmed to react to them.

09:16.720 --> 09:18.000
This is something that we'll use

09:18.000 --> 09:19.600
throughout the rest of the course,

09:19.600 --> 09:21.760
and all the complex schemes that we'll create

09:21.760 --> 09:23.200
will rely on messages.

