GoalPlan a program with several sprites, give each sprite its own script and test that every part works.
New words
plan · a description of what you will make before you make ittest · to try a program to find out whether it does what you wantcomment · a note in a program that explains what the code does
Explanation
A band program has several sprites. Each sprite has its own script that starts with its own trigger. Scripts that start with the green flag run at the same time. Scripts that start with a key press wait for that key. First make a plan with a table. For each sprite write what starts it, what it does and how it repeats. Then build the scripts and add comments. Finally test every part. For each test write what to press and what you expect to happen. If the result is different, you have found a bug to fix.
Sprite
Starts when
What it does
Loop
Drummer
d key pressed
snare drum, rest
repeat (8)
Guitarist
g key pressed
note C, then note G
repeat until s is pressed
Dancer
green flag clicked
switches between two dance costumes
forever
Worked examples
Here are the scripts for the drummer and the guitarist. One round of the drummer takes 0.25 + 0.25 = 0.5 beats, so 8 rounds take 4 seconds. One round of the guitarist takes 2 beats.
The dancer starts with the green flag and never stops by itself. It switches to its next costume every half second, so it seems to dance to the music.
Test
What to do
What should happen
1
click the green flag
the dancer dances; no sound
2
press d once
8 drum hits in 4 seconds, then silence
3
press g
the guitar plays C, G, C, G…
4
hold the s key for 2 seconds
the guitar stops at the end of its round
A test plan says what to do and what should happen.
Class activity
Plan your band (in a group of three): draw a table with the columns sprite, starts when, what it does and loop. Choose three sprites such as a drummer, a singer and a dancer. Each person writes one script on paper using the Scratch blocks from this unit. Swap scripts and trace each other’s work. Then write three tests: what to press and what should happen. One person is the conductor and calls out the keys. The others act out the scripts. Does everything work as planned?
Practice
1
In the band plan, which key makes the drummer play, and how long does the drum part last?
The d key. The drum part lasts 4 seconds, because 8 rounds of 0.5 seconds make 4 seconds.
2
The plan says that the singer starts when the v key is pressed. Tom presses v and nothing happens. Find the bug and fix it.
The hat block says when b key pressed. Change it to when v key pressed, then test again by pressing v.
3
Write a test for the guitarist: what do you press and what should happen?
For example: press g. The guitar plays C and G again and again. Press and hold s. The guitar stops at the end of the round.
4
Write a comment for the dancer script that tells a reader what it does.
For example: “The dancer changes costume every half second, again and again, until the stop button is clicked.”