Week 2 · Unit 1: Making programs clear · 3 lessons
2
Reset the start place
Computing 3: Unit 1, pp. 8–27
GoalUse the go to block to put a sprite back at its start place every time the green flag is clicked.
New words
reset · to put something back the way it was at the startx position · how far left or right a sprite is (negative is left)y position · how far up or down a sprite is (negative is down)
Explanation
A program can move a sprite. Click the green flag again and the sprite begins where it stopped last time, not where it began. This is a problem. To fix it, add “go to x: y:” straight after the hat block. The two numbers say where the sprite must start. Take care with the minus sign: x: −180 is on the left, but x: 180 is on the right. A short wait block after it lets you see the sprite at its start place before it moves.
Worked examples
A boat is placed at x: −180. The program is “move (200) steps” and the boat faces right. The first click takes it to x: 20. With no reset, the second click starts at x: 20 and goes to x: 220. It keeps drifting towards the edge.
The minus sign matters. The block go to x: (−150) y: (0) puts the fish on the left side. If you forget the minus sign, go to x: (150) y: (0) puts it on the right side.
A block go to x: (−100) y: (80) means 100 to the left of the middle and 80 up. The y number matters too. The picture shows where the sprite will stand.
Class activity
Paper stage: draw a long line on paper and number it from −4 on the left to 4 on the right, with 0 in the middle. A coin is the sprite. The program is: go to x: −3, then change x by 2, then change x by 2. Do the steps on the line and write down where the coin finishes (x: 1). Run it a second time without the go to step and see where the coin ends up. Which version always finishes in the same place?
Practice
1
The sprite faces right. The program is: when green flag clicked, go to x: (−120) y: (0), move (50) steps. Where is the sprite after the first click? And after the second click?
At x: −70 both times. The go to block puts it back at x: −120 before it moves 50 steps.
2
A sprite is placed at x: −120 facing right. The program has no go to block: when green flag clicked, move (50) steps. Where is it after 3 clicks?
At x: 30. It moves 50 each time: −120 + 50 + 50 + 50 = 30.
3
A sprite must always start in the middle of the left edge. Which block goes right after the hat block: A, B or C?
A. It puts the sprite at x: −200, y: 0, which is on the left, in the middle. B is on the right, and C moves the sprite but does not reset it.
4
Why is a wait block useful after a go to block?
The computer is very fast. A short wait lets us see the sprite at its start place before it moves away.