Game+Score+Example+(part+1)

Game Score Example (part 1)
Consider a programmer writing a computer game which has to display the player's score. The programmer would create a variable called **//score//**. The variable **//score//** would change ( **+100** ) every time the player shoots an enemy spaceship. The variable **//score//** would change (** -30 **) every time the player loses a life.

At the start of the game, the programmer would have to set an initial value for the variable **//score//**. As this is the start of the game, the **//score//** would normally be ** 0 **. Setting a value at the start of a game is called initialisation.

The easiest way to think of a variable is to imagine it like a box with a name, and a value inside it. Using the example above, the name of the box would be score. And the value in the box at the start of the game would be 0.

Game Start
At the start of the game, the programmer would set the variable **//score//** to the value 0.

This is known as **assignment**, because the programmer is assigning the value of 0 to the variable score.

When variables are assigned a value at the beginning of a program, this is also known as **initialisation**.



The Scratch code for this is:

The Real Basic code for this is:

Shoot Spaceship
When the player shoots an enemy spaceship, they get 100 points added to their score. Remember, the **//score//** is currently 0, so the new value in the box will be 0 + 100, which is 100.



The Scratch code for this is:

The Real Basic code for this is:

Lose Life
When a player loses a life, they have 30 points taken off their score. Remember, the score is currently 100, so the new value in the box will be 100 - 30 which is 70.



The Scratch score for this is:

The Real Basic code for this is:

Writing the program
Now go here to write the program in Scratch or go here to write the program in Real Basic.