Set and change variable blocks

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Set and change variable blocks

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which block puts a starting value into the score variable at the start of a game?
A set score to 0
B change score by 0
2. What does 'change score by 1' do when score is 4?
A Score becomes 1
B Score becomes 5
3. Which block makes the score jump back to 0 for a new game?
A change score by 1
B set score to 0
4. A player loses a life. Lives is 3. Which block makes lives go DOWN to 2?
A change lives by -1
B change lives by 1
5. Where should 'set score to 0' usually go in a script?
A Near the start, under the green flag
B Inside the loop, every time a point is scored

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1set score to 0 Aset lives to 3
2change score by 1 Bchange lives by -1
3Counting down: take 1 life away each time the player is hit CThe score was never set to 0 at the start, so it keeps the old value from the last game and the count will be wrong. Add set score to 0 first.
4Setting at the start: give lives a starting value of 3 when the game begins DAdds 1 to the number already stored in score, so the score counts up.
5when green flag clicked change score by 1 (no set block first) EThe set block replaces the score with 1 every time instead of adding to it. Use change score by 1 to count up.
6set score to 1 (used to add a point each time a coin is touched) FStores the starting value 0 in the score variable, so the game begins with a score of zero.

Definitions

set score to 0

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
___ score to 0 change score by 1
2.
when green flag clicked set score to _
3.
when space key pressed ______ score by 1
4.
set lives to 3 change lives by __
5.
when this sprite clicked change _____ by 1

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A when green flag clicked
B set score to 0
C change score to 1
D say score
Question 2
A set score by 0
B change score by 1
C change score by 1
D say score
Question 3
A when green flag clicked
B change lives by 3
C change lives by -1
D say lives
Question 4
A when green flag clicked
B set score to 0
C change score by 1
D change points by 1
E say score
Question 5
A when green flag clicked
B set timer to 10
C change timer by 1
D say timer

Answer Key

Set and change variable blocks
Section A: Quick Questions
Q1
A — set score to 0
Q2
B — Score becomes 5
Q3
B — set score to 0
Q4
A — change lives by -1
Q5
A — Near the start, under the green flag
Section B: Match the Pairs
Q1
set score to 0 → Stores the starting value 0 in the score variable, so the game begins with a score of zero.
Q2
change score by 1 → Adds 1 to the number already stored in score, so the score counts up.
Q3
Counting down: take 1 life away each time the player is hit → change lives by -1
Q4
Setting at the start: give lives a starting value of 3 when the game begins → set lives to 3
Q5
when green flag clicked change score by 1 (no set block first) → The score was never set to 0 at the start, so it keeps the old value from the last game and the count will be wrong. Add set score to 0 first.
Q6
set score to 1 (used to add a point each time a coin is touched) → The set block replaces the score with 1 every time instead of adding to it. Use change score by 1 to count up.
Section C: Definitions
Q1
set score to 0 — A variable block that stores a starting value in score. Use change score by 1 to add to it, or by -1 to take away, so the score counts up or down.
Section D: Fill in the Blanks
Q1
set score to 0 change score by 1
Q2
when green flag clicked set score to 0
Q3
when space key pressed change score by 1
Q4
set lives to 3 change lives by -1
Q5
when this sprite clicked change score by 1
Section E: Spot the Error
Q1
C — The change block adds to a variable, so it must say 'by'. It should be 'change score by 1'. The word 'to' belongs in the set block.
Q2
A — The set block stores a starting value, so it uses 'to'. It should be 'set score to 0'. The word 'by' belongs in the change block.
Q3
B — At the start, lives needs a starting value, so this line should use a set block: 'set lives to 3'. A change block only adds to what is already stored.
Q4
D — The program uses a variable called score, but this line changes a different variable called points. It should be 'change score by 1' so the score keeps counting up.
Q5
C — A countdown needs to take away from the timer. Changing by 1 adds, so the timer would count up. It should be 'change timer by -1'.