video

Lesson video

In progress...

Loading...

Hi, I'm Rebecca, and I'm going to be your computing teacher for this unit.

If you're unsure about using sequence selection and iteration in Scratch, then it's recommended that you do the programming essentials in Scratch, Part One unit before doing this unit.

For this lesson, you're going to need a Scratch account, and if you're under 13, you will need to get a teacher, or parent, or carer to set one of those up for you.

You're also going to need a pen and a paper.

So if you can make sure that you try really hard to remove any distractions out of your way so that you can focus today, then we can begin.

In this lesson, you will define a subroutine, define decomposition, and you'll create your own subroutines, as well.

So to get started, this is a little challenge for you.

I want you to make a prediction.

So take a look at this programme that is on your screens, and think about what might happen when this programme is executed.

What's going to happen to that sprite? So write it down in your notebook.

And also, you're going to need to pause while you have a think about that, so do that now.

Fantastic, so hopefully you've got your prediction now, and we're going to check that out in Scratch to see if you were right or not.

So here is that programme from the starter activity now in Scratch, and we've got here blocks, and we've got here Scratch, the cat, so I'm going to click the green flag, and I'm going to see what happens, to see if our predictions were correct or not.

So here we go.

Right, so Scratch the cat went up and went back down again.

So were you correct? Thumbs up or thumbs down, what was it ? Hopefully, it was a thumbs up, but don't worry if it was a thumbs down.

Let's have a look at this programme and just to see what's happening.

So we've got there, when green flag is clicked.

So hopefully, you already know now that when green flag is clicked, that is going to be the first instruction that happens underneath.

And it's got this jump block there, and if you look there, we've got define Jump at the top which is our subroutine, so it's calling a subroutine called Jump, so it's going to here, and then it's running the instructions that are inside this subroutine.

So change Y by Y means move up 50, and then wait one second, it's just going to pause for a second, and then change Y by minus 50 is going to make it go down.

So let's just look at it one more time.

And that is what our subroutine is doing.

So what we just saw there was a subroutine, and custom blocks in Scratch are called subroutines.

Subroutines are a group of instructions that will run when called by the main programme or other subroutines.

Subroutines allow us to use a piece of code again and again whenever we call them.

And we're going to act out some subroutine calls, just to have a little practise.

When I call out a subroutine name, I want you to carry out the action.

So we've got on there four subroutine calls.

We've got jump, wave, wiggle, and dance, and what I want you to do is just think, well, what actions could I carry out for those four subroutines? So jump, you don't have to jump out of your chair or anything like that.

You could just do a bounce, like this.

Wave could be like this, or like this, or a wave.

Wiggle, you could wiggle your body or do a wiggle movement with your hands, and dance, do your best dance moves, whatever you've got in your repertoire there, in dance moves, you can do your best dance moves.

So just pause the video, just have a tiny little think and a little practise about what those four moves are going to be, and then we're going to have a go at calling them out together.

So just pause now and have a think.

All right, are you ready? So we're going to do this together.

I'm going to do it as well, all right? So when I call out a subroutine name, so if it's wiggle, then I want you to wiggle, I want you to do whatever instruction you decided to do for your dance move, and the same for all of the other ones, and I'm going to call them out in any order, at any point, and we're going to do this together, okay? So off we go, so, wave, wave, jump, wiggle, wiggle, jump, wave, dance, jump, wiggle , wave, wave, jump.

Okay, that's enough, that's all right.

Hopefully, you were doing that with me, and it wasn't just me on my own.

But hopefully, you've seen there that when we call a subroutine, it doesn't matter about the order, and it doesn't matter how many times we call it.

We can just call it whenever we want, and those instructions are repeated again and again and again.

So we only have to write them once, and then they can be repeated.

So once a subroutine is written and working, that's a good point that it has to be working, the instruction inside become less important.

Subroutines help break down a problem into small, manageable chunks, and this is known as decomposition.

This is something that we're going to learn more and more about the more we practise it and learn about programming.

It's a skill that you'll develop.

Here is a problem that we can try and solve.

So a programmer wants to create a character that will perform different dance moves to a song.

The dance moves will form part of a dance battle game where players perform the best moves to earn points.

So what I'd like you to do is have a think about this.

How could the programmer decompose this problem? So remember, decompose, or decomposition, means breaking a problem down into small, manageable chunks.

So have a little think, and think about the starter activity and the dancing activity that we just did, and see if you can think, well, how could this programmer decomposes this problem, so, break it down into small, manageable chunks? So pause the video.

You can write it down as well, if you want to, and just have a think about that.

Fantastic, so hopefully, you've had a little think about that now.

What I would have thought is they could break it down by having a subroutine for those different dance moves.

And this is what the programmers thought as well.

So the programmer would like to have four different dance moves, and wants a subroutine for each one.

And you're going to be using a worksheet to help you design those four moves, 'cause you're going to have a go at this too, and this is the worksheet, you can access this later, and this is what it looks like.

So your sprite has nine costumes in total, and these are shown on the next two slides.

So if you look at all those costumes, all sprites have got costumes, which you can have a look at, and this one's got nine.

So those are the different moves that it can make, and then here are the other four.

Those are just some different moves, so you can study these when you're looking at the worksheet yourself.

And what you're going to do is you're going to use the costumes and any other instructions to design a subroutine for four dance moves.

An example has been created for you.

And again, this is on the worksheet for you to have a look at.

So an example move might be that it switches to Costume 1, and then it's going to move up.

Now, you don't need to write the actual Scratch instructions.

You can just literally put Move up, that's fine.

Switch to Costume 3, Move down, and then Switch to Costume 6.

So that's just some brief notes about what that move is going to do, so it's just breaking that problem down into manageable chunks.

And then in your worksheet, you're going to see this.

Now, you don't have to write on the worksheet and print it off.

You can just get your pen and paper out, and you can just draw and write those four dance moves on there.

So what I want you to do is pause the video, and I want you to design those four dance moves, and use the worksheet to help you design it.

And when you're finished, and you're ready, then you can come back and resume the video.

Hopefully, by now, then, you've planned your four dance moves on your worksheet, and you're ready to get going with creating them in Scratch.

So what I'm going to do is, I'm going to do a demonstration in Scratch just to show you the start programme, and how it works, and how to make your own subroutines, and then you're going to have a go at making your own, based on the designs that you have made.

So if you type in ncce.

io/DanceBattle into your browser, then you will get Dance Battle programme, our start programme, and this is how it will open for you, and you can just select See inside, and then you can see all the code that you've got there and the start project.

You can also see that you've got Jordyn there, and you've got her costumes that you can have a look at, those nine costumes.

They're all there from the worksheet that you can use to design your own subroutines.

So we've got some start code as well, to help you out, to get you started.

So I can actually run this game.

So let's just press Go and just see what happens.

So you might be able to hear that, there's a little bit of music that plays in the background.

Now, we've got here, when A pressed, do these things and when S pressed, do these things.

So if I press A, then Jordyn does a little twist and a little jump, and then if I press S, then Jordyn does just the twist on its own.

So let's just stop that, and turn the music off.

So we've got there two subroutines already made for you, so you can use those ones as a guide or you can delete them, but I would probably keep them there just while you're getting started just so that you can get used to it.

And then you've got here, you've got those key presses, and then the subroutines are being called underneath.

So if you want to make your own subroutine, you just go to My Blocks, and you can see those two subroutines calls are already there, the ones that have been made.

If I go to Make a Block, and let's just do that simple one from the starter activity, so just a basic jump, and I'm going to make the sprite go up and down, so I'm going to change Y by 50, and then I'm going to wait one second, and I'm going to change Y by minus 50.

And if I run this programme now, what do you think might happen to jump? Let's just see what happens.

Hmm, how do I get that jump to actually work? It's not being called, is it? So there's a little problem here.

I've made my subroutine, but I haven't called my subroutine, so in order for my subroutine to actually run, I've got to call it as well, so I might just add it to this S one, so when S is pressed, it's going to twist, and then it's just going to do my standard jump that I've got there.

So I go to My Blocks again, and that call has been added, that block, because I've made the block now, and I can go here and just attach it to the bottom.

So now when I run the code, if I type the S on my keyboard, it's going to do that twist, and then it's going to do that basic jump that I did there.

So you can add things on to the bottom of these key presses, or you can make your own key presses by adding in the events and finding different key presses, and then just adding your jump to that, so when space bar is pressed, it's going to jump.

So use your design that you have got to help you make it.

So what I'd like you to do is pause the video so that you can complete this task.

So you're going to create your four moves in Scratch, and you're going to use that short link to find the Scratch programme, and you're going to.

If you want to, you can add more complex moves and try and match the moves to the beat as well.

So if you want a little bit of an extra challenge, you can try and do that, too.

So resume the video when you are finished.

Now that you've created your four subroutines for your dance move, it's now time to start thinking about how you could extend the game.

So I'm going to do a demonstration just to show you a few tips for extending the game, and then I'm going to give you some time to actually extend it yourself.

So let's take a look in Scratch.

So here is that game again in Scratch.

Now, you've probably noticed that you've got two characters that you can use, two sprites, so you've got Jordyn and you've got Ben.

So you've done all your hard work.

You've made those subroutines for those four dance moves, but now you want to make Ben do those dance moves as well.

So you don't have to spend ages copy and pasting or writing it out, because you can just drag those blocks onto the new sprite.

So I'm just going to show you how to do that.

So take it in turn.

So grab it and then drag it on, and you'll see that it just moves.

It wobbles a little bit as you pull it over, so once it wobbles a bit, you know that you're in the right place, and then let go, and then it'll just jump back here, but it will still be there on the new sprite, Ben.

So if I just do this again, and I do it again, and I do it again, I should then have four blocks of code in the Ben one.

So if you look, it does put them all on top of each other, so you could move them as you're doing it, or you could just wait till the end and then move them all around.

So there we go, I've got my subroutines now.

So exactly the same subroutines are on Jordyn and on Ben.

Now, when I run this code, what do you think is going to happen? Just have a little think what's going to happen.

How is it going to actually work? So let's just run it, and let's just see what happens when I press A.

So I'm pressing A.

Hmm, they both move at exactly the same time when I press A.

And the same thing's happening when I press S, and that's because we haven't changed the controls for the other player.

So if this is going to be a fun game for two players to play, we're not going to want exactly the same controls for those two players, so what I can do now is I can choose different controls.

So if I look at the other side of the keyboard, I've got a P and I've got an O on the other side of the keyboard, so I could have O for this one, and I could have P for this one, and now, when I run it again, only Jordyn moves when I press A, and when I press S, but when I press O and P, then Ben moves.

So that's just one way that we can extend the game.

We could also add a score for different dance moves if we wanted to, so that it could actually.

when somebody gets to, maybe, a score of 10, the game's over, and that person's won.

So have a think about it.

Think about how you might extend the game, and you can have a little bit of time to do that now.

So here are your instructions for extending the game, and just some ideas for you to think about, and I want you to pause the video when you complete the task, and then when you're ready to resume, just come back to the video and press Play.

Great, so hopefully, you've come up with some really cool dance moves for your game, and you've got maybe two players working as well, and it's starting to look really fun, and fun to play.

So we're just going to have a little round-up, with a little quiz at the end, just to see what you remembered about those three key things that we were looking at today.

So what I want you to do is just take a look at these three questions, and then write the answers to them on your pen and paper.

So have a little think about them, see if you can remember the answers, and write them down, and then we'll review them after we've paused the video.

So pause the video now.

Great, so question one, why are subroutines useful? So hopefully you have something like, they allow code to be written once and used as many times as they are needed.

So that's why they're useful.

You might have also said they're useful for decomposition, as well, or something like that, and that's fine, as well.

That would be corrected too.

So question two, how can subroutines be used for decomposition? So hopefully, you've got something like this: We can break the problem down into manageable chunks.

Each problem can be solved with a subroutine.

So hopefully you've got something like that.

If you've just put breaking it down into manageable chunks, then that's great as well.

That's good remembering for today, well done.

And how do you create a subroutine in Scratch? Well, you create a custom block.

You might have drawn the block, you might have wrote something a little bit different there, but that is what you'd do.

So hopefully, that tested you a little bit, and prepared you for the quiz at the end.

So we'd really, really love to see those Scratch programmes that you've made today, and if you'd like to, please ask your parent or carer to share your work on Instagram, Facebook, or Twitter, tagging @OakNational and #LearnwithOak, if you want to share those Scratch resources with us today.

So well done, you've been fantastic, you've worked really hard today.

I hope you're very proud of your Scratch programmes that you've done, and we'll see you again soon.