# Lesson video

In progress...

Hello and welcome to lesson one of our variables in games unit.

I'm Andy and this lesson is going to introduce you to variables.

So for this lesson, you'll need a web browser and access to the Scratch website.

If you'd like to save your work, you'll need an account, if you don't have a Scratch account and you're under 13, you'll need to get your parent, carer, or teacher to set an account up for you.

You'll also need something to write on and something to write with.

So if you'd like to clear away any distractions that you may have in front of you, we can start.

In this lesson you'll recognise that a variable is something that is changeable, you'll identify examples of information that is variable, you'll be able to explain that the way a variable changes can be defined, you'll also identify that variables can hold numbers or letters.

So, we're going to start by thinking about an international football game, the USA versus Japan, and we're looking at the scoreboard and as the game goes on, the score changes.

One nil to the USA, two nil, two one, and the game ending three one.

And we can see those two numbers, those two values there.

So those two variables are related to the score, one for the USA and one for Japan.

When a goal is scored, the value of the variable changes.

In this example, it's a number that changes.

So, for your first task, I'd like you to try out this Scratch project.

You're going to have a look at it and click on things and see what happens, so there are three different colour balls on screen and you're going to try clicking on each of those colour balls and watch what happens.

A key thing to watch out for is in the corner it says score, that's what's going to change.

So I'd like you to watch out for what changes, when it changes, and is the change always the same? And for this task you don't need to look at the code inside the Scratch project.

So if you'd like to pause the video now, you can try that first task.

So this is the project I asked you to look at.

If I click on one of the balls, the project starts and you can see in the corner a score box appeared with the number zero.

If I click on the yellow ball, the score is changing, and each click it's changing by one.

If I click on the purple ball, the score changes again, but this time each click makes the score change by three.

If I click on the green ball, again the score changes, but this time it decreases, it goes down by one with each click.

So as you tried out that Scratch programme, you saw that a variable, the score, can be set and changed throughout the running of a programme.

So what I'd like you to do now is look inside the project itself to see how it works, we can do that by clicking on these four arrows which takes us out to full screen and into the project page.

If I then click see inside, I can see what's going on inside the project.

We can see the three balls and we can see the three sprites, each of those balls, and on this ball is the code, when the sprite is clicked, change the score by one.

If I go click on ball three, it says when this ball is clicked, change the score by three.

And on the green ball it says when the green ball is clicked, when this sprite, the green ball is clicked, change the score by minus one.

So your next task is to go into the project, have a look through it, and then actually change those values so that when each sprite, each ball is clicked, the variable, the score variable changes by a different amount.

So at the minute it's one, I can change that and put something different.

So pause the video now, now have an activity to do.

So you need to change the code so that when each sprite is clicked on, the score variable changes by a different amount.

So pause the video now.

Okay, I hope that went well.

So you were asked to change it so that the yellow ball being clicked on would change the score by two, so your code should've looked like that and the pink ball being clicked on was to change the score by 10, so your code should've said change score by 10 and lastly, the green ball, when the green ball was clicked on that was to decrease the score and it was to decrease it by two, so your code should've read change score by minus two, so each time two was taken away from the score.

So in the last task you followed a design, you were told how much to change things by, this time you're going to create your own design.

So on a piece of paper, you need to choose three sprites, if you write those down, this has got a cat, a dog, and a bird.

The event will be that the sprite is clicked on and that is the same for each of them, that's given for you, and then you choose how much the variable will change by.

So when the cat is clicked on, add two to the score, when the dog is clicked on, add five to the score, and when the bird is clicked on, reduce the score by three each click.

So, you need to pause the video in a moment and create your own design, choosing your sprites and the amount to change variables by, so pause the video now.

Okay, so now you should have your own design, you should've listed the three sprites that you want to use and the fact that when you click on each of those sprites something happens and how much the variable will change as each one is clicked on.

So I'm going to move to Scratch now and show you the first steps of your task.

Okay, so now you're going to create your own Scratch project following the design you've got on your piece of paper.

So to create our own project, we need to go to file, new and that will start a new project, the old one's gone.

So if I click on choose a sprite, I can add them and you'll end up with your three sprites here.

Once you've got your sprites sorted, you need to create your variable and set it so that clicking on the sprites makes the variable change.

So if I go to variables, the very top option is make a variable, I click on that, it's got new variable name and I'm going to call my variable score, as we've been using that before.

And I don't need to change this, it needs to be the same for all sprites, they're all going to be able to change this variable score.

I click on okay, I now have a variable score shown here and it appears on my screen there so I can see it.

So the event that will make the variable change is that when the sprite is clicked, so for each sprite I'll need this when hat, when this sprite is clicked, and then if I go back to variables, I want to be able to change the variable, not set, I want to change it, and it says change my variable.

Well, I've made a variable but it's not called that, my variable is called score, so I need to change this to score.

So when the sprite is clicked, change score by, say it was five.

So each time now, when I go and click on the cat, my variable should change by five and I can check and test that's working there.

Great, so hopefully you've done that, here's my project, I have a cat, a dog, and a bird and if I look at the cat, here's the cat sprite, when the cat is clicked on, change the score by two, and I can try that, watching the score, two.

And the dog, when a dog is clicked on, change the score by five, so I can try that, adding five every time.

And lastly, the parrot, that, so I've got 28 there, it was to take three off, so each click on the parrot will take the score down by three, so if I try that, that's it, the score's now going down.

So, that's my project completed.

Okay, so if we finish by thinking back to the start of the lesson when we looked at a scoreboard and we identified that it had a score on it, it actually had two variables, one was the home score, the other was the away score and these were numbers.

There are also variables for the teams because these could be changed in a different game.

In this example, the home team is USA and the away team is Japan.

Just like scores, they can change and in this example, rather than being numbers, they are letters.

So here's another example showing it's changed, in this example the home team value is ESP or Spain, the home team score is zero.

The away score is zero and the away team's variables value is ENG for England.

So, your last task is to have a look at the worksheet and work out what the values of the variables are on the examples shown.

So please pause the video now and go to the worksheet.

Great, so I'm sure you didn't find that too tricky.

So when we are looking at the values in A, so this was the scoreboard A, the home team variable was GER, Germany, GER, the home score was zero, the away team was MEX, Mexico, and the away score was one.

Okay, and then the other example, so values in B, in this example, the home team was SWE, Sweden, the home score was three, the away team was South Korea, KOR, and the away score was one.

Great, so that's the end of this lesson.