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

Term 3 review

Week 30 · Review: Term 3 · 3 lessons
2

Review: game scripts and messages

Computing 6: Units 9–12, pp. 124–177
GoalRecall how scripts, variables, messages and test plans fit together in a game.
New words
broadcast · a block that sends a named message to all spritesvariable · a named place where a program keeps a value that can changetest plan · a table of tests with expected and actual resultscustom block · a block that you define once and use many times
Explanation

A game is built from several scripts that work together. One sprite can broadcast a message when something happens, for example when it touches a prize. Another sprite has a script that starts with when I receive the same message, and it changes the score. A variable such as score is set to 0 at the start, and then it changes as the game goes on. A custom block holds steps that we use in many places, so we write them once and fix them once. When the game is built, we run a test plan. Each test has an input, an expected result and an actual result. If they are different, there is a bug to find and fix.

Birdwhenclickedbroadcastcaughtwait1secondsiftouchingWorm?thenforeverScorerwhen I receivecaughtchangescoreby2
Worked examples
TouchMessageScore
start—0
1caught2
2caught4
3caught6
Trace the game. The score starts at 0. The bird touches the worm three times. Each time the message caught is sent and the scorer adds 2. The score goes 2, 4, 6, so it ends at 6.
DefinitiondefinecheersayWell done!for1secondschangecoloreffect by25Usewhen I receivecaughtcheer
This custom block is defined once. Every time the game needs it, one call runs all its steps. If we change the words in the definition, every call changes too.
ScoreExpectedActualResult
2Keep goingKeep goingpass
6You win!You win!pass
7You win!Keep goingFAIL
The game says You win! when the score is 6 or more. The test plan checks the edge of the rule. The test with 6 is the boundary. The test with 7 fails, so the condition probably says score = 6 and not score > 5.
Class activity

Human game (no computer): make the game with people. Two children are sprites. The bird touches a card with a worm drawn on it and calls out caught. The scorer hears the message, adds 2 to the number on the board and calls out the new score. Play until the score is 10. Then change a rule, for example adds 3 instead of 2, and decide which script you have to change. Why do we only change one script? If you have a computer or tablet, build the two scripts in Scratch.

Practice
1
A frog catches 3 flies. Each time the message caught is received, the score goes up by 5. The score starts at 0. What is the score at the end?
when I receivecaughtchangescoreby5
2
Why is it better to send a broadcast message than to copy the scoring blocks into every sprite?
3
The game should say You win! for a score of 6 or more. Look at the tests. Which test fails and what is the likely bug?
ScoreExpectedActual
4Keep goingKeep going
6You win!Keep going
9You win!You win!
4
The same dance is used in four places in a game. How can a custom block help?