Loading...
Hi I'm Rebecca, your computing teacher.
And today we are going on a treasure hunt.
So you're going to need your Scratch account for that and you're also going to need your pen and paper so that you can keep track of all your answers in today's lessons.
So also don't forget, really important, get rid of any distractions that you can just so it can help you focus today.
So when you're ready, let's begin.
In this lesson you will describe the purpose of a list, identify when to use a list, and you will use a list.
So before we start what I want to do is just refresh your memory on what we did in lesson three.
And I want you to tell me which loop is best and why? So a programmer wants to draw a single pentagon in Scratch.
So using your pen and paper I want you to write down what you think is the answer and explain why.
So pause the video now while you do that.
Awesome, so this is my answer, this is what I decided.
So I went for that middle one.
And the reason that I went for that middle one is because it does the job, it works.
But also it's using that repeat five.
So it's going to just draw the side and turn.
And then it's going to repeat that five times to draw a pentagon.
If I'd use the left one which was the forever loop, then it would just keep drawing a pentagon over and over and over and over again until I stopped the programme which wouldn't be exactly what I needed.
And then the other one, it does work but it's a lot more complicated.
It's going to take much longer to write that programme and think about it than if I just used that repeat five loop that just does all that extra thinking for me.
So that's why it's the best one to use in that scenario.
Okay so looking at lists, so introducing lists.
Variables can hold one piece of data at a time.
But what happens if you need to hold more than one piece of data? You might want to create a shopping list programme for example.
You couldn't do this with a variable because it would just overwrite the previous shopping item each time.
Lists allow you to hold multiple items of data under one name.
And I'm going to show you an example now by going into Scratch.
Here is a shopping list programme in Scratch.
So let's just take a look at the code and see if we can make a prediction about what might happen.
We've got here when green flag clicked, populate shopping list.
So that is a call for a subroutine and it's for this subroutine here.
And what it's doing first of all.
Oh gosh, well you've probably seen this one set item to, so that's a variable and it's setting it to blank.
We've got a bit of a new block here that you won't have seen before, delete all of shopping list.
So that might be deleting, if there's something in the shopping list it might be deleting it.
And then it's asking what shall I add to the shopping list? It's waiting and then the answer is being held in item.
And then something's being added to a shopping list and that seems to happen three times.
I think, my prediction, in fact you just have a little pause and you just see if you can make a prediction first of all before we run the code.
Awesome so let's run the code now and see what actually happens.
So I'm going to press the green flag.
And it says what shall I add to the shopping list? Which is this block of code here, what shall I add to the shopping list? So if type bread there and press the enter key, you can see that it says set item to answer.
So my answer has been held in this variable here, bread.
And then the next one add item to shopping list.
You can see here I've got a list and this is what a list looks like in Scratch.
So the list is called shopping list.
And that item that was held in answer, so that value there bread has also been held in the shopping list.
So what happens when I add my second one in? So I'm going to put milk.
So I put milk in and now item has been replaced with milk.
So this is why a variable isn't helpful when we're doing a shopping list.
Because it just overwrites the value.
So that bread has disappeared now and it's been overwritten with milk.
So now milk is held in the variable item.
You can also see with that next block of code there add item to shopping list, what it's done is it's added that extra item that I just entered there into the shopping list.
So now I've got two items in my shopping list.
So let's just do one more.
What could I buy from the shops, I can't even think, cheese.
So again it's replaced the item there so now cheese is being held in item in that variable.
But milk has gone and bread isn't there because every time it's overwritten.
And now cheese is also because we've got add item to shopping list.
Cheese has also been added to the end of that list.
So a list allows you to hold multiple items of data which become really really useful with some of our programmes.
Now we're going to be seeing how lists can be used as part of a game.
So we're going to start looking at this treasure hunt game that I was talking about at the start of the lesson.
So familiarise yourself with this game by experimenting with it for five minutes.
Don't get too lost in it, I want you to come back and carry on with the lesson.
Work out how to get to the next level.
Either through game play or through reading the code.
So in our last few lessons in lesson two and three, we've done lots of investigating the code and reading the code to try and figure out how it actually works.
So you can put those skills into practise now and see if you can read the code to try and figure out how to get to the next level.
Or you can just play around.
Don't worry too much about it and if you can't figure it out because we are going to go through it in a little while.
So there's your short link and that should take you to the Scratch programme.
And you'll see there there's quite a lot going on.
We've got some blocks of code here and we're on the Scratch character.
There's lots and lots of sprites on this one so you might want to have a look at the code there.
But what I want you to do is I want you to spend five minutes or so just playing the game.
And if you want to you can look in the code as well and see if you can figure out how to get to the next level.
So pause the screen and then once you've had your five minutes, I want you to come back and look at the rest of the video.
To figure out how this programme works and also to learn about lists, you're going to do an investigation.
And this worksheet is just very slightly different to how the ones have worked in lesson two and three.
We're going to have a little practise so you can see what I want you to do.
And then you're going to have a go by yourself working independently.
So it's the same link, we don't need to worry about that.
And then we've got this time the worksheet is broken down into two stages.
So you've got an instruction for most of them and then you've got a question as well.
So the instructions just tell you where to move Scratch the Cat to and then he asks you a question.
So I want you to keep an eye on things as you're moving around so you can start to learn about what is actually happening.
So the first instruction is you're going to view the goblin sprite code.
You've got to press the green flag and you've got to read what the goblin has to say.
And the question is what is currently being held in the inventory list? So we're doing those instructions and then we're going to look at what is held in the inventory list.
So let's go and have a go.
So the first instruction was to view the goblin code.
So I'm going to go to that and make sure I can see it, there's the goblin code.
And then it said press the green flag and read what the goblin has to say.
So pressed it.
To get to the next level you need to give the centaur a few items. I have one of them with me but I need an object first, okay.
It doesn't say anymore than that.
It then says what is currently being held in the inventory list? That's the question we've got to answer so if you take a look, nothing is being held in the inventory list at this point in time okay.
So that's the answer to our first question.
Question two then has some instructions before it.
So we've got walk towards the goblin, read what the goblin has to say.
Look at the code for the goblin and it says what needs to be in the inventory list for the goblin to give you a diamond? So remember that inventory list was blank.
But hopefully in the code it will give us a clue as to what needs to be in there for the goblin to give this diamond.
So let's go and have a look.
I'm going to walk Scratch the Cat to the goblin to see what happens.
I'm walking, walking, oh there we go.
You don't have the item I need, that's what the goblin says.
So every time I think I walk up to the goblin, it's going to say you don't have the item I need okay.
So let's look at the goblin code.
This is all that's happened already.
These were the things that were said at the very beginning and then you can notice that it's now stuck in this forever loop.
Because those first bits have happened and now the forever loop is there.
And it says wait until touching Scratch.
So because it's in a forever loop, every single time I go to touch the goblin with Scratch the Cat, some lines of code are going to run.
So let's look at what's underneath.
It says if inventory contains apple, so if inventory contains apple.
Now does inventory contain apple? Let's have a look.
No it doesn't because the inventory is empty at the moment.
But if it did, it was going to run these blocks of code.
But because it's not it's going to that else and it says you don't have the item I need and that's what's happening at the moment because apple, because it's something not in there, the apple.
So if we have a look you can see there so if inventory does contain apple, it's going to run these sections of code here.
And this can look quite confusing and it is a little bit confusing to look at.
But it says set index to item number of apple in inventory.
It's holding a value in index wherever apple is held.
And at the moment apple is not held so this line of code isn't working.
And it says replace that index item with a diamond.
So actually I think what I need to do is get the apple in order to get the diamond from the goblin.
But the instructions on the worksheet don't say to do that yet so I'm just going to look at the next question.
Question three has got some instructions to carry out beforehand.
So it says click on the apple sprite to view the apple code and walk to the apple, avoid objects.
That's very important with this worksheet is that you avoid objects.
So follow the instructions exactly as it tells you to, otherwise things might go a little bit wrong.
And then question three says what happens to the inventory list when Scratch touches the apple? So we've got to look at the apple code and we've got to see what happens when Scratch touches the apple as well.
Let's go and have a look.
I'm going to click on the apple sprite then.
And I'm going to make sure that I can see the code.
There's not very much code for the apple sprite.
So then the next instruction was to walk towards the goblin and see, no not the goblin it was the apple.
Let's go find the apple.
Making sure I avoid any of those other objects that are there.
So I'm going to walk to the apple.
Ah did you notice that? So up here in the inventory list apple has now been added to the inventory list.
And if you look at the code here you can see it says wait until touching Scratch, that's a very similar bit of code that was there on the goblin.
But it's not in a forever loop this time, it's just sitting and waiting.
And it says add apple to inventory.
So that line of code there must add items to a list.
Okay so that's what it's done.
Question four doesn't have any instructions with it.
So we just go straight to answering the question.
It says write down the piece of code that is used to add apple to the inventory list.
So if you remember on the apple sprite you can see that block of code that said add apple to inventory.
So that is that block of code that was used.
So hopefully that's just given you an idea of how this works.
Make sure that if there are instructions do those first.
Don't go ahead as well.
I know it's quite tempting to try and keep going ahead as you start to see what's going on.
But make sure you follow those instructions and you answer the questions in the correct order so you don't get lost.
So what I want you to do now is try this independently.
Use your worksheet to go through some more instructions and some more questions by yourself.
But please don't worry if you find some of them a little bit tricky to answer.
I'm going to explain them all afterwards.
So if you have found it hard or just want to know if you got it right or not, then I'll explain that once you're done.
So pause now and get on with that task independently.
Was that fun trying to figure it out? So what I'm going to do now is I'm going to go through some of the answers to those questions and just talk you through just in case you weren't sure about some of them.
So the first instruction when I left off was click on the monkey sprite to view the code.
Walk to the monkey, avoid objects, remember that one? And then it says what does the monkey say when you touch it? And question two is what item needs to be in your inventory for the monkey to say thanks for the watermelon? I'm on the monkey sprite so I can see the blocks of code.
And then I've got to walk towards the monkey and see what it says.
So it says I really love watermelon.
So every time I go to the monkey it says I really love watermelon.
So if we look at the code there it's fairly similar to the goblin code in the sort of the structure because it's got forever, it's got a wait until touching scratch, it's got an if and it's got an else.
And at the moment it's going straight to that else saying I really love watermelon.
But if we go to this first one it says if inventory contains watermelon.
At the moment it doesn't so none of this code is running.
It says thanks for the watermelon and then it's saying set index to item number of watermelon to inventory, delete index of inventory, okay.
Again those two lines of code seem a little bit confusing as we start to see this.
But we can see it's doing something.
But I think we're not going to really know until we start having those items in our inventory and we actually see what those lines of code do.
So it needs to have the watermelon in order for the watermelon to disappear from the inventory.
The next two questions focus on the watermelon and the monkey.
So I've got to go to the watermelon, view the code, and walk to the watermelon.
Where does the item watermelon appear in the inventory? So we can look at that.
Then it says click on the monkey sprite to view the monkey code and walk to the monkey.
What has happened to the watermelon item in the inventory list? So we're going to have another look at what happens there.
So the watermelon code is saying, it's got this again hasn't it? This wait until touching Scratch, add watermelon to inventory.
It's this same line of code, add watermelon to inventory.
That was on the apple code as well wasn't it? So if we walk towards the watermelon, and if we take a look at the inventory list you can see that watermelon has been added.
And watermelon to be added at index number two.
So apple is index number one and watermelon is at index number two.
So let's go back to the monkey code and let's just walk to the monkey and see what happens now.
Just going to move my screen, my camera out of the way, there we go.
So let's just go up.
So keep an eye on this list here.
So we've got one apple, two watermelon, what's going to happen when I go to the monkey? It says thanks for the watermelon and the watermelon has disappears from the inventory list.
So if we look there, that's the line of code that we saw that was quite obvious, thanks for the watermelon.
And then it says set index to item number of watermelon.
So set index to item number of watermelon, that's going to be number two.
So set index to two.
And then it says delete two of inventory.
And that's what's happened there.
It's found out what location the watermelon is at which is number two and then it's deleted whatever item is at that location.
So question number five wants you to follow the instructions first.
It says find this block of code in the monkey sprite.
So that's the one we were just looking at.
And it says this block of code checks for the index location of the watermelon, and then it deletes the item that is in that location.
What was the list item number for the watermelon? And if you remember it was number two.
Where was the index number held for this block of code to work? And it was held in the index variable.
Okay so hopefully you got that.
The next one there is to look at question six.
And the instructions are click on the goblin sprite to view the code and walk to the goblin.
What is now being held in the inventory list? Okay so let's see what happens next.
Here is the goblin code there and it's asked us to walk towards the goblin and see what happens.
So we've got apple there at the moment, is something going to happen? Thanks for the apple, here is the diamond.
So did you notice there that apple got replaced in the inventory with diamond? So it says this block of code does two things, describe those two things for question seven.
So it's looking at in the instructions there you've got the screenshot of the blocks.
So it says set index to index number of apple in inventory, replace item index of inventory with diamond.
So hopefully those two lines of code are making a tiny bit more sense to you now.
They might not be making 100% sense which is fine.
But hopefully you're starting to understand it a little bit more.
So this block of code does two things, describe those two things.
So that first line is finding out the index of apple.
And remember apple is at location one.
So the number one is being held in the index variable.
So it's set in the index variable to whatever location the apple is in, which is one in this case.
And then it says replace item index, so that means item one of inventory with diamond.
So whatever was held in item one, which was the apple is going to be replaced with the diamond.
So that's what those two lines of code actually do.
So instruction eight then, click on the present sprite to view the code, walk to the present.
And it says describe what happens when Scratch touches the present.
And the other one which items are now in the inventory list? Okay so describe what happens when Scratch touches the present.
Which items are now in the inventory list? Let's have a look.
I'm on the present sprite or the gift sprite and I'm going to walk towards the present.
Okay so now in the inventory list we've got diamond and we've got present.
And present is being added at index location two.
The next question is to find out what condition needs to be true for the player to go to the next level.
And you might have even figured this out before you even got to this question here.
It says click on the centaur sprite to view the code, walk to the centaur.
Okay so let's see what happens.
There's a lot of code here on the centaur sprite but hopefully it's going to help me see what needs to happen to get to that next level.
So I'm going to go all the way over to the centaur.
What's it going to say? Well done, you found the items, off to the next level.
So I must have met all of the conditions in order to go to the next level.
So let's take a look at those conditions, it's quite a long one.
So you've got here an if statement.
And it says if inventory contains present, and inventory contains diamond, which it does.
If you look there diamond and present.
Then it says and not watermelon.
So that means it can't have watermelon or else it's not going to go to the next level.
So if you've got present and diamond, then it's going to go to the next level.
But if watermelon is in your list there somewhere then it's not going to take you to the next level.
But because I had diamond and present and nothing else, it's letting me go to the next level.
Instruction 11 is saying to press the green flag to restart the game.
And then it's saying to collect the apple, diamond, present, and watermelon.
Don't give it to the monkey and then walk to the centaur.
And then it says what does the centaur say when you have the watermelon in your list? So let's go and have a look.
I'm going to stop it then, I'm going to start it again and I've got a fresh level now.
And it says started again with my goblin telling me that he needs a few items. So I'm going to go and get the apple.
I'm going to get the present.
I'm going to get the watermelon and I'm going to go to the centaur.
It says I can not eat watermelon, you can not move on until I have my items. I can not eat watermelon.
You can not move on until I have the items. Oh it keeps repeating itself over and over again.
Because I'm right next to it if you look.
As soon as I come away it stops.
So that's what happens, it says I can not eat watermelon.
Question 12 then is saying click on the cake sprite to view the code and then what action does the cake sprite currently do? And then you're being asked to modify the cake block and the cake is needed for the next level.
Using the code from the apple sprite as a guide, add the cake to the inventory when it is touching Scratch the cat.
Let's have a go at that.
Here is the cake code then.
At the moment it's hiding a next level and it's showing when green flag is clicked.
And it says wait until touching Scratch.
So it's a bit of start code there.
Let's have a look at the apple code just to see what we might be able to use.
So on the apple code, have to wait until touching Scratch.
It says add apple to inventory and then it says hide.
So I think probably have to do something similar to that.
So I go to cake, I'm going to stop the code.
I'm going to go to the variables and I'm going to go to, there we go it says add thing to inventory.
So add and this time it's a cake so add cake to inventory.
And then the last bit that it was missing was hide.
Because once it's been picked up you want it to disappear.
So we go to looks and we get the hide block.
So now when I walk over to the cake, yep, when I walk over the cake, the cake disappears and cake is added to the inventory.
So I've done some modifications as well.
That investigation then should have given you a little bit more of an idea of how this will actually work.
And some of the code blocks that you can use with lists.
So what we're going to do now is we're going to have a little practise.
And don't worry if you don't get all of these right because it is still brand new to you.
But let's see if you can guess what each block of code does.
So here we go, we've got match the description to the correct code block.
So which code block there deletes all items in a list? So I'm just going to give you a few seconds to have a look at those.
Or you can pause it if you want to if you want a little bit longer.
And just think about which code block on the right is going to delete all items in the list, have a look.
All right so here is the answer.
So it's that bottom one, it says delete all of inventory.
So that's going to delete everything from the list.
So what does the next one say? Adds an item to the end of the list.
Okay so let's look down, see what you think it might be.
Have a little pause.
Okay what's the answer? Yeah so add present to inventory.
That line of code there is going to add an item to the end of the list.
And then it says checks if the list contains a specific word.
Okay so let's have a look.
Which one do you think? Here's the answer.
So it says inventory contains present.
So that is going to be looking as a condition to check if inventory contains present.
And if it's true it's going to return true and otherwise it's going to be false.
So it's condition there.
So the next one deletes a single item in a specific location.
Now we saw this one quite a lot in our code didn't we? In our treasure hunt game.
So deletes a single item in a specific location, which one is it? It's this one okay.
So delete item of inventory.
So if it knows what the item is then it's going to delete it.
And then the final one it's quite obvious now which one it is.
So replaces an item at a specific location with another item.
This one was a tricky one.
Remember we first looked at this line of code and how difficult it was to understand.
Hopefully you're starting to understand what this line of code does now.
So yeah it was that last one.
It was quite obvious it was the only one left.
But hopefully now you're starting to look at these blocks of code and you're starting to be a little bit more familiar with how they actually might work.
And may be thinking about how you might use them yourself as well.
The one you see now is have a go at a Parsons puzzle.
And what a Parsons puzzle is is it gives you all of the blocks of code that you need to solve a problem.
But they're all mixed up and in the wrong order.
And what your job is to have a look at the problem and read it carefully and decide what order those blocks of code need to be in in order for it to work correctly.
So what I want you to do is go back to your worksheet, go to the bit where it says a Parsons puzzle.
And you can have a look at the problem on there and you can read it carefully.
And then you can try and decide what order the blocks need to be in.
You do not need to draw the blocks on your piece of paper.
You can just write the words that are in the blocks, that's absolutely fine.
So have a go and see how you get on.
So pause the video, find the worksheet, and have a go at putting those blocks in the right order and then come back when you are done.
Awesome well done.
Here it the answer so see if you got it right.
So it should be when green flag clicked, delete all of inventory.
Add peach, add melon, wait until touching apple, and then replace item one of inventory with banana.
So hopefully you got that right.
Give me a thumbs up or a thumbs down whether you got that right.
Hopefully, maybe half right you never know.
So hopefully you've learned a lot about lists today and you're getting more familiar with them and more comfortable with using them.
And I hope you enjoy playing with that game as well, the treasure hunt game, it's quite a fun one.
If you'd like to please ask your parent or carer to share your work on Instagram, Facebook or Twitter, tagging @OakNational and #LearnwithOak.
Because we really love it when you modify these programmes that we've given you and then you make them your own.
So it'll be fantastic to see what you have done today with that work.
Well done.
I hope that you've found that useful and I'll see you soon.