Unit B · Telling a computer what to do
What we are making: a sprite you drive with the arrow keys. From here on, the person using your program is part of it.
Everything on the screen has two numbers: how far across it is, and how far up. Across is called x. Up is called y. The middle of the stage is x 0, y 0.
Go right and x gets bigger. Go left and it gets smaller, and past the middle it goes negative. The stage runs from about −240 to 240 across, and −180 to 180 up.
Those separate scripts feel jerky, because Scratch waits a moment before repeating a held key — the same pause you get holding a letter down in a word processor.
The fix is the shape you met last session: forever with if inside it. Now the program checks the keys itself, as fast as it can, instead of waiting to be told.
| What you see | Why | What to do |
|---|---|---|
| The sprite does not move at all | The green flag script is not running. | Click the green flag. The forever version needs it; the key-pressed version does not. |
| It moves in jerks | You are still using the four separate scripts. | Use forever with if inside. That is the whole point of this session. |
| It goes off the edge and disappears | Nothing is stopping it. | Scratch keeps a sliver visible. Drag it back, or add an if that checks x. |
| It moves diagonally on its own | Two scripts are fighting. | Delete the old separate key-pressed scripts once the forever one works. |
In this session