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

Plan before you code

Week 9 · Unit 4: Be a storyteller · 3 lessons
3

From plan to scripts

Computing 5: Unit 4, pp. 44–57
GoalTurn each event of an outline plan into a small script and check that every event has one.
New words
subprogram · a small script that is part of a larger program; it carries out one event’s outcomehat block · the block at the top of a script; it names the event that starts the scriptscript · a stack of blocks that start with a hat blockcheck · to look again to see that nothing is missing or wrong
Explanation

Each event in the plan becomes a subprogram: a small script that starts with a hat block for that event. The green flag becomes ‘when green flag clicked’. A click on a sprite becomes ‘when this sprite clicked’. A key press becomes ‘when space key pressed’, and a message becomes ‘when I receive’. A change of backdrop becomes ‘when backdrop switches to’. The blocks under the hat are the outcome. A script belongs to one sprite, so select the right sprite before building it. When all scripts are built, tick each row of the plan, and test each event one at a time.

Event in the planHat block
the green flag is clickedwhen green flag clicked
a sprite is clickedwhen this sprite clicked
a key is pressedwhen [space] key pressed
a message arriveswhen I receive [message1]
the backdrop changeswhen backdrop switches to [backdrop1]
Worked examples
Rocketwhenclickedswitch backdrop toSkysayReady for launch!for2secondsRocketwhen this sprite clickedglide2secs to x:0y:120switch backdrop toMoon
The Rocket needs two scripts, one for the green flag and one for its own click.
AstronautwhenclickedhideAstronautwhen backdrop switches toMoonshowsayWe made it!for2secondsAstronautwhen this sprite clickedstart soundPophide
The Astronaut needs three scripts: one for the green flag, one for the backdrop and one for its own click. It starts hidden. Then it shows when the backdrop switches to Moon.
A script must be on the right sprite. If the ‘when this sprite clicked’ script for the Rocket is put on the Astronaut by mistake, nothing happens when the Rocket is clicked. Always select the sprite first, then build its scripts.
Class activity

Script cards (3 or 4 players). Cut the plan table into strips. Make a hat-block card for each kind of event. Match every strip to a hat-block card and to a sprite. Then act out the program. One player is the stage manager who reads out the events in order: green flag, Rocket clicked, and so on. The other players are the Rocket and the Astronaut and say or do the outcomes. Swap two strips. Which scripts no longer work? If you have a computer or tablet, build the rocket program in Scratch.

Practice
1
Choose the hat block for each event: (a) the green flag is clicked, (b) the player clicks the sprite, (c) the space key is pressed, (d) the backdrop changes to Moon.
EventHat block
a?
b?
c?
d?
2
Which sprite should have the script ‘when backdrop switches to Moon: show, say We made it!’? Why?
3
Complete the algorithm for the Astronaut’s click.
StepInstruction
1?
2?
3?
4
In the lesson’s rocket program, the player clicks the flag, then the Rocket, then the Astronaut. What do you see at the end?