AdvertisementYour brand could be hereYour brand hereOn every Darslab page · students, parents and teachersinfo@darslab.comAsk for pricesPricesinfo@darslab.com
☰ Year plan · Computing

Mix and test programs

Week 3 · Unit 1: Making programs clear · 3 lessons
3

Build, reset and test

Computing 3: Unit 1, pp. 8–27
GoalBuild a short program that resets itself, then run it twice to test that it works.
New words
test · to run a program and check that it does what we wantedrun · to start a program so it follows its blocksoriginal · the way something was at the very start
Explanation

Here is a plan for a good program. First decide the start place and the start size. Put “go to” and “set size to” straight after the hat block. Then add the action blocks. Next, join any blocks that repeat. Last, test the program: run it twice. If the sprite ends in the same place, with the same size, both times, the reset works. A short program that resets itself is a good program.

whenclickedgo to x:-100y:-100set size to100%wait1secondschange y by100change size by-20
Worked examples
ClickNo reset: yNo reset: sizeWith reset: yWith reset: size
1st080080
2nd10060080
A kite program starts at y: −100 and size 100 and climbs 100 steps while shrinking 20. Look at the first two clicks. Without a reset the kite climbs higher and shrinks more each time. With a reset it is always at y: 0 and size 80.
whenclickedchange size by-20set size to100%
The reset blocks must come first. In this program the set size block is last. It puts the size back to 100 at the end, so the shrinking is cancelled and the sprite is always size 100. The red block is in the wrong place.
To test a reset, run the program once and write down where the sprite stops. Run it again. If the place and size are the same, the reset works. If they are different, something is missing.
Class activity

Test it on paper (with a friend): the program is “go to x: −3, change x by 2, change x by 2” on a paper number line from −4 to 4, with a coin as the sprite. Run it twice and check that the coin ends in the same place both times. Then remove the go to card and run it twice. What happens the second time? Write down what you see.

Practice
1
A sprite follows this program. Where is it, and what size is it, after the first run? And after the second run?
whenclickedgo to x:0y:-80set size to100%change y by40change y by40change size by30
2
Write a more concise version of the program in question 1. How many blocks does it have?
3
Find the mistake. The sprite should always start at x: −100.
whenclickedchange x by30go to x:-100y:0
4
A kite starts at y: −80 and climbs 100 each run. There is no reset. After the first run it is at y: 20. Where is it after the second run?