GoalPlan a program with two sprites that each have their own scripts and predict what happens when they meet.
New words
interact · to affect each othersprite · an object in a Scratch programpassword · a secret word or phrase that lets you in; it must be kept secretsafe · protected from harm or from other people
Explanation
Most programs have more than one sprite, and each sprite has its own scripts. The scripts can run at the same time. One sprite may move while the other waits and checks. A condition can use the other sprite, such as ‘touching Tortoise’. We plan each sprite with the questions from the last lesson, then predict what happens when they meet. If … then is also used for passwords: if the password is correct, then let the person in. A password must stay secret. Make it long and hard to guess, and tell it only to a parent or carer.
Worked examples
Question
Tortoise
Flag
Is it static?
no
no
What actions?
moves 20 steps
checks all the time
Input
right arrow key pressed
green flag clicked
Condition
none
touching the Tortoise
Conclusion
none
says Winner! and stops all
A program has a Tortoise and a Flag. The player presses the right arrow key to move the Tortoise. The Flag keeps checking, and when the Tortoise touches it, the Flag says ‘Winner!’ and stops the program.
Here are the scripts. The Tortoise has a start script that puts it at x: -100, and the Flag stands at x: 100. The Tortoise moves 20 steps for each press, so after 10 presses it reaches the Flag and the Flag says ‘Winner!’.
Selection is also used to protect passwords. The program asks for the password. If it is correct, then it lets the person in. If it is not correct, it does nothing.
Class activity
Sprite theatre (3 players). Two players are sprites and one is the stage manager. The Bus starts at one end of a line of 8 floor squares and the Stop stands on square 6. The stage manager says ‘key’, and the Bus takes one step. The Stop watches the Bus all the time and says ‘Board here!’ the moment the Bus is on its square. After the Bus has arrived, the stage manager says ‘flag’ and both players go back to their starting squares. Try again with the Stop on square 4.
Practice
1
The Bus starts at x: -60 and moves 30 steps for each press. The Stop is at x: 60. On which press does the Stop say ‘Board here!’?
On press 4. The Bus is at -30, 0, 30 and then 60 after presses 1 to 4.
2
A Child moves with the arrow keys. A Puddle says ‘Splash!’ whenever the Child touches it. Complete the plan.
Question
Child
Puddle
Is it static?
?
?
Input
?
?
Condition
?
?
Conclusion
?
?
Child: not static, moves with the arrow keys, input arrow keys pressed, no condition, no conclusion. Puddle: not static because it keeps checking, input green flag clicked, condition touching the Child, conclusion says Splash!.
3
Write the algorithm for the Puddle in numbered steps.
1 Start when the green flag is clicked. 2 If the Puddle is touching the Child, then say ‘Splash!’ for 1 second. 3 Repeat step 2 forever.
4
Which is the safest password rule? (a) use your birthday, (b) make it long and hard to guess, and tell only a parent or carer, (c) use your pet’s name and tell your best friend.
(b). Birthdays and pet names are easy to guess, and a password should be secret from everyone except a parent or carer.