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

Build, test and reset

Week 15 · Unit 6: Be an animator · 3 lessons
2

Start from the same place

Computing 5: Unit 6, pp. 70–85
GoalExplain why objects must be reset when a program starts, and write a start script that resets them.
New words
reset · to put something back the way it was at the startoriginal state · how an object looks and where it is when the program beginsstart script · a script that begins with the green flag and puts objects in their starting statedirection · the way a sprite is pointing; 90 points right
Explanation

After a program has run, its sprites do not go back by themselves. A sprite may stay at the other side of the stage, stay hidden or stay big. If we run the program again, it begins in the wrong state. To prevent this, give each sprite a start script. It begins with when green flag clicked. It sets the position, the size, the costume, the direction and whether the sprite is shown. The start script and the other scripts of a sprite are separate scripts. Test by running the program twice.

whenclickedgo to x:-180y:-100point in direction90set size to60%show
Worked examples
RunTaxi’s x at the start, no start scriptTaxi’s x at the start, with a start script
1-180-180
2120-180
The Taxi moves 50 steps for each right arrow press. It starts at x: -180. After 6 presses it is at x: 120. Without a start script, the second run begins from x: 120, near the edge of the stage. With a start script, every run begins at x: -180.
Block that changes itBlock that resets it
change size by (10)set size to (100) %
hideshow
next costumeswitch costume to [costume1 v]
turn ↻ (15) degreespoint in direction (90)
move (10) stepsgo to x: (0) y: (0)
A block that changes a property has a block that puts it back.
Tortoisewhenclickedgo to x:-150y:-80set size to80%showTortoisewhenright arrowkey pressedmove20stepschange size by10hideiftouchingLettuce?then
The Tortoise has a start script and a key script. The key script makes it bigger and hides it when it touches the Lettuce. Without ‘show’ in the start script, the Tortoise would stay hidden in the next run.
Class activity

Reset the stage (pairs). Draw a stage on paper and cut out a Mouse and a Coin. Write three program cards: ‘Mouse moves 3 squares for each press’, ‘if the Mouse is on the Coin, then hide the Coin’ and ‘Mouse grows’. Play the program until the Coin disappears. Now play again without resetting. What goes wrong? Write a start card that puts everything back, and play again.

Practice
1
A sprite glided to the top of the stage, hid itself and grew by 20. Write the blocks that reset it.
2
Fill the empty block so that the Whale begins at its normal size.
whenclickedgo to x:0y:0?show
3
Why does a program often work the first time without a start script?
4
The Bee moves 40 steps for each press. It starts at x: 0 and is pressed 3 times. Where does a second run start without a start script? Where does it start with ‘go to x: 0 y: 0’ in a start script?
whenright arrowkey pressedmove40steps