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

Selection in Scratch

Week 14 · Unit 6: Be an animator · 3 lessons
3

Plan the object first

Computing 5: Unit 6, pp. 70–85
GoalPlan the instructions for an object by answering questions about its purpose, input, condition and conclusion, and then write its algorithm.
New words
object · a sprite or other thing in a programstatic object · an object that has no code and stays where it isinput · the event that starts a script, such as pressing a keyalgorithm · a set of steps in order that solves a problem
Explanation

Programs with selection are bigger, so we plan each object before we write the code. Ask these questions. Is the object static, with no code? What actions does it need to do? What is the input, the event that starts its script? What is the condition? What is the conclusion? Then write the algorithm in numbered steps and build it from the steps. Last, test the program and debug it. A plan on paper is easy to change, so mistakes cost less time.

Worked examples
QuestionKiteTree
Is it static?noyes
What actions?flies 25 steps rightnone
Inputright arrow key pressednone
Conditiontouching the Treenone
Conclusionsays Stuck! for 2 secondsnone
A program has a Kite and a Tree. The player presses the right arrow key to make the Kite fly. If the Kite touches the Tree, it says ‘Stuck!’. Here is the plan for each object.
StepAlgorithm for the Kite
1Start when the right arrow key is pressed.
2Move 25 steps.
3If the Kite is touching the Tree, then say ‘Stuck!’ for 2 seconds.
4Stop.
Next, the plan becomes an algorithm. The Kite also has a start script, which puts it at the left of the stage when the green flag is clicked.
Kitewhenclickedgo to x:-160y:60Kitewhenright arrowkey pressedmove25stepssayStuck!for2secondsiftouchingTree?then
Last, each step becomes a block. The Kite starts at x: -160. After 9 presses it is at x: 65. The Tree stands at x: 65, y: 60. Then the condition is true.
Class activity

Plan a pair (2 or 3 players). Choose one moving object and one static object, for example a boat and a lighthouse, or a robot and a charging station. Fill in a planning sheet with the questions from the lesson for each object. Then swap sheets with another group. Cut out two paper objects, put them on a grid on the table and act out the plan: one player presses a ‘key’ by tapping the table, and the other moves the paper object and checks the condition each time. Does the plan work? Is any question left blank?

Practice
1
A Boat sails to a Lighthouse. When the player presses the space key, the Boat moves, and if it touches the Lighthouse it says ‘Safe!’. Which object is static? Which object has an input?
2
A Camel moves 20 steps each time that the space key is pressed. If it touches the Oasis, it says ‘Water!’. The Oasis stays still. Complete the plan.
QuestionCamelOasis
Is it static???
What actions???
Input??
Condition??
Conclusion??
3
Write the algorithm for the Camel in numbered steps.
4
Match each part of the plan to a block in this script: input, action, condition and conclusion.
whenup arrowkey pressedchange y by20hideiftouchingLeaf?then