A Programmer's Guide to Scratch 3
Written by Lucy Black   
Monday, 27 April 2020
Article Index
A Programmer's Guide to Scratch 3
Hello World
Bounce a ball demo
Expressions and Variables
Where to Scratch next?

Your First Program - Hello World

You will see a multi-pane IDE with the Scratch cat graphic in the white area called the Stage. Scratch is a language that is mostly about working with Sprites that are controlled by the scripts you write - which are listed in the Scripts area. You don't create scripts by typing in commands but by dragging and dropping selected blocks listed in the blocks area to the Script area.




So to get started what better way than with a traditional "Hello World" - which is not the best way to get a complete beginner started because it lacks any great excitement!

First we need to specify when the script should be run.

Scratch doesn't come with a default "main" routine which is the entry point for all processes. Instead you associate scripts with various starting events. 

In other words Scratch is an event oriented language - blocks do things in response to events.

In the case of our first script let's start it when the green Go Flag, at the top of the Stage area, is clicked. This isn't the only way of starting a script but it is the one that corresponds to a programmers expectation of there being a Run button.

There are so many blocks that you can use to build a program that they are organized into palettes that you have to select to see what is available. 

To see the When "green flag" clicked block you have to select the Events palette of blocks:



In the list of control blocks drag-and-drop the top one that starts when the green flag is clicked:




Next we need a block that makes the sprite do something.  Select the Looks palette of blocks and drag-and-drop the one with the label say Hello!




Now you have a complete program but you need to change the message from Hello! to Hello World. Click on the text within the block and you should find that you can enter a new message. The program should now look something like:




If you now click on the green flag above the stage area then the script will run and the Sprite1 will display a speech bubble with Hello World in it: 


That's all there  is to it. You have your first working Scratch program. It should now be easy for you to explore the blocks that are available to construct more complex scripts.

There are a few points to make clear.

The first is that you associate a script with a particular sprite by selecting it in the Sprite List. You can have multiple sprites and the scripts determine the behavior of each one. You can think of the scripts that belong to a sprite as its methods if you want to emphasize object-oriented programming. However don't be tempted to introduce advanced ideas too quickly there is plenty of time to start calling things objects and scripts methods later.



Last Updated ( Monday, 27 April 2020 )