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

Term 2 review

Week 21 · Review: Term 2 · 3 lessons
2

Selection and sprites

Computing 5: Units 5–8, pp. 58–118
GoalReview if … then in Scratch: plan a sprite, predict what a script does, find bugs and start every sprite from the same place.
New words
selection · a decision in a program, made with an if blockcondition · a question that is either true or falseconclusion · the blocks that run when the condition is truestart script · a script that puts a sprite back in its starting state
Explanation

Selection means that a program makes a decision. An if block holds a condition, and its conclusion is carried out only when the condition is true. If the condition is false, the program skips the conclusion. Inside a forever block the condition is checked again on every pass. To predict a script, work through it one pass at a time and write down each change. Before we build, we plan each sprite with four questions: its purpose, its input, its condition and its conclusion. Every sprite needs a start script, so that each run begins from the same place. When a program has two sprites, each has its own scripts, and a condition can use the other sprite.

Plan questionAnswer for a Star sprite
Purposeto be collected by the Rocket
Inputthe green flag is clicked
Conditionthe Star is touching the Rocket
Conclusionthe Star hides
Worked examples
Rocketwhenclickedgo to x:0y:-140change y by20ifkeyup arrowpressed?thenforever
The Rocket starts at y: -140 and moves up 20 whenever the up arrow key is held. On passes 1 to 4 the key is held and on pass 5 it is let go. The Rocket goes up 4 × 20 = 80, so it ends at y: -140 + 80 = -60.
Starwhenclickedgo to x:100y:50showhideiftouchingRocket?thenforever
The Star has this script. While the Rocket is far away the Star stays visible, because the condition is false. When the Rocket touches it, the Star hides. When the Rocket moves away again the Star stays hidden, because nothing inside the loop shows it again.
BugWhat you seeFix
the if block is outside the forever blockit is checked only oncemove the if block inside the loop
the start script has no show blockthe sprite stays hidden on the second runadd show to the start script
the wrong sprite is selectedthe script has no effectdrag the script to the right sprite
These are common bugs. Each one has a clue and a fix.
Class activity

Sprite plan cards (pairs). Draw a 3 × 3 grid on paper as the stage. One player is the Rocket and moves one square when the other player says ‘key pressed’. The second player is the Star, who stays on a square and says ‘hide’ if the Rocket is on the same square. Write a plan card first with purpose, input, condition and conclusion. Play, then reset both pieces to their start squares. Why is the reset needed before a second game?

Practice
1
The Bee is at x: 0, y: 0. The right arrow key is held on 6 of 8 passes. Where is the Bee after 8 passes?
Beewhenclickedgo to x:0y:0change x by15ifkeyright arrowpressed?thenforever
2
Plan a Door sprite that changes its costume when the Child sprite touches it. Give the purpose, input, condition and conclusion.
3
The Crab touches the Shell after 3 seconds but never says Munch. Why? How can it be fixed?
CrabwhenclickedsayMunchfor2secondsiftouchingShell?thenmove2stepsforever
4
A sprite hides when it is touched. On the second run it is still hidden at the start. Which block is missing, and from which script?