Solution Development:
Introduction to Scratch
– a Graphical Programming Tool
1
Pre Knowledge
Created a variable
Assigned a value to the variable (to be able
to save that data for later use).
Basic assigning and recalling of the variable.
2
Exploring data types
Scratch makes use of two data structures to represent
variables:
1. Variable – This data structure can only hold a single value
under a single name
2. List – This is a data structure that can hold more than one
value using the same name. This will be discussed at a
later stage.
3
Variable
It is not necessary to declare what data type will be used before
running the program. Scratch will automatically determine the
data type of variable while the program is running.
Numbers String Boolean
Any characters e.g. Cat /
Any number e.g. 8 or 6.91 True/False
Town
Can be used to do Can’t be used to do Can’t be used to do
calculations calculations calculations
If a number variable is
expected for calculations and
String manipulation can be
a string is included in that
done to the values e.g. Used in decision-making
variable, Scratch will then
Adding the Name and steps
assign a value of 0 to that
Surname together
variable. The program will
NOT be stopped.
Numbers – In Delphi we are going to make use of Integers (whole numbers) and
Real (decimal numbers) Scratch handles numeric values in the same way.
4
Naming conventions of
variables
Scratch does not have strict rules with the naming of variables, but other
programming languages do. When you create a variable the following facts
need to be considered, especially to get used to it for when we move over
to Delphi in Grade 11.
Don’t use any spaces within the name, rather capitalize each word in a
phrase e.g. Number of Fruit – should be one word NumberOfFruit.
Make use of the Underscore symbol if you want to link words e.g.
Number_Of_Fruit.
The name must be descriptive of the data expected in the variable.
Start the variable name with a alphabetical character and NOT a
symbol or number.
5
Naming conventions of
variables
To make it easier for you to remember and get used to:
Make use of the following characters for the first letter of your
variables:
Characte Use Example
r
i When your variable is a integer / iNumberOfPeople
whole number
r When your variable is a real value rAmountToPay
s When your variable is a string/text sName
b When your variable is a Boolean type bPaid
(yes/no)
Scratch will work no matter what the naming convention.
It is just easier for future use.
6
QUESTION
Suggest a better naming convention for each of the following:
Name Of Player
1Person
YourAgeThisYear
!Failed or not ?
7
ANSWER
Suggestions of a better naming conventions:
Name Of Player sPlayerName
1Person Gender sGender
YourAgeThisYear iAge
!Failed or not ? sPassed
8
Viewing of variables
The variables that you have created can be set to
be visible in the program or not.
By clicking on the checkbox next to the variable
name it can be made visibly on the stage.
9
Viewing of variables
There are different views when the variables are
visible.
By right-clicking on the variable on the stage, gives
you a menu
10
Viewing of variables
The user can manipulate the variable in the slider
mode by clicking and dragging the pointer left-right.
So the user can use the mouse as input.
11
Viewing of variables
These views can also be changed by double-clicking
on the variable on the stage.
12
Viewing of variables
The Slider option has more settings when you right-
click on the variable on the stage:
13
QUESTION
Why would you change the sliders maximum
and minimum values?
14
ANSWER
Why would you change the sliders maximum
and minimum values?
If a set range is expected in the variable.
E.g. Enter your Grade :
15
ANSWER
Answer is a variable that is created by
default by Scratch.
It is used to get a value from the user
in a structured way.
Scratch automatically determines the
data type as soon as it is entered. The
programmer doesn’t have to prescribe
the data type.
16
QUESTION
Can the variable also be
viewed on the stage?
In all 3 different views?
17
ANSWER
Can the variable also be
viewed on the stage? YES
In all 3 different views? NO
18
QUESTION
Why can’t the be viewed in the
slider mode?
19
ANSWER
Why can’t the be viewed in the
slider mode?
Because the programme can not
determine that the answer will be an
integer value. Sometimes the answer
is text.
20
QUESTION
Can you rearrange
and move the
variables anywhere
on the stage?
21
ANSWER
Can you rearrange
and move the
variables anywhere
on the stage?
YES 22
QUESTION
Can the viewing of the variables be
shown/hidden and vice versa while the user
is using the program?
23
ANSWER
Can the viewing of the variables be
shown/hidden and vice versa while the user
is using the program?
YES
24
Assigning values to
variables
In mathematics we usually assign a value to a
variable:
x=y
In Scratch we use a similar way by stating:
And if we get the answer from the user, we
assign the variable this way:
25
Complete worksheet
26