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

Scripts that run together

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

Timing with wait

Computing 3: Unit 4, pp. 60–78
GoalWork out how long a script takes and use a wait block to make two sprites finish together.
New words
glide · to move smoothly to a place, taking some secondstiming · when things happen and how long they taketotal time · all the waits and glides added together
Explanation

Some blocks take time, and some do not. “go to x: y:” happens at once. “wait (1) seconds” takes 1 second. “glide (2) secs to x: y:” takes 2 seconds. “say [Hi!] for (2) seconds” takes 2 seconds. To find the total time of a script, add up the blocks that take time. If two scripts start together but have different times, the shorter one finishes first. To make them finish together, add a wait block to the shorter script.

BlockTime it takes
go to x: y:no time
wait (1) seconds1 second
glide (2) secs to x: y:2 seconds
say [Hi!] for (2) seconds2 seconds
Worked examples
whenspacekey pressedgo to x:0y:0wait1secondsglide2secs to x:100y:0sayDone!for1seconds
This script goes to a place, waits 1 second, glides for 2 seconds and then says “Done!” for 1 second. The total time is 1 + 2 + 1 = 4 seconds. The go to block takes no time.
Boatwhenspacekey pressedgo to x:-150y:-50glide3secs to x:150y:-50Fish (fixed)whenspacekey pressedgo to x:150y:-120wait2secondsglide1secs to x:-150y:-120
The boat glides for 3 seconds. The fish glides for only 1 second, so it arrives 2 seconds early. We add “wait (2) seconds” to the fish script. Now the fish waits 2 seconds, then glides for 1 second, and both finish after 3 seconds.
Dancer Awhenspacekey pressedwait1secondssayHi!for2secondsDancer Bwhenspacekey pressedsayHello!for3seconds
Two dancers can also take turns to speak. Dancer A waits 1 second and then speaks for 2 seconds. Dancer B speaks for 3 seconds. Both scripts take 3 seconds in all, so they finish together.
Class activity

Stopwatch game (with a friend): one of you is the boat, who walks across the room taking exactly 3 seconds. The other is the fish, who must finish at the same moment. A stopwatch or counting “one thousand one, one thousand two…” helps. How long must the fish wait before starting if the fish walk takes 1 second? Try it and check that you arrive together.

Practice
1
How many seconds does this script take?
whenspacekey pressedgo to x:-100y:0wait2secondsglide1secs to x:0y:0wait1seconds
2
Script A takes 5 seconds and script B takes 3 seconds. They start together. Which finishes first? What can we add to B so that both finish together?
3
Both scripts start when the space key is pressed. Do they finish at the same time? Which sprite starts speaking first?
Awhenspacekey pressedwait1secondssayHi!for2secondsBwhenspacekey pressedwait2secondssayHello!for1seconds
4
Which blocks take no time?