Send the link below via email or IMCopy
Present to your audienceStart remote presentation
- Invited audience members will follow you as you navigate and present
- People invited to a presentation do not need a Prezi account
- This link expires 10 minutes after you close the presentation
- A maximum of 30 users can follow your presentation
- Learn more about this feature in our knowledge base article
Do you really want to delete this prezi?
Neither you, nor the coeditors you shared it with will be able to recover it again.
Make your likes visible on Facebook?
You can change this under Settings & Account at any time.
Transcript of Lesson Two
In the previous class, we defined object oriented programming and the concept of objects. In this class, we will be discussing the properties of objects otherwise called variables or attributes and how they are useful.
Objects have data fields called attributes. Attributes detail the property of an object with a stored value that is generally referred to as variable.
The five blocks relating to variables are as follows:
Types of Variables
Use of Variables
The ScratchWiki (2013) suggests that Variables should be used whenever a value must be stored in a program. As illustrated above, this value could be anything including the scores of a user in a game.
The score of a particular player can be retrieved at any time and all the all the project needs to do is check the score that corresponds to a particular users name.
In Scratch, you use the “Make a var” button in the Variables palette to create variables.
A variable is a changeable value recorded in Scratch's memory. Variables can only hold one value at a time. These values can be either numbers or strings i.e. any text.
For example the color attribute of a ping pong ball stores a “color" value. Possible values are white, blue, green, etc. Its position may also be defined as another attribute called "position" with variables such as position "x", or "y".
We shall go ahead and create an object and then define its attributes.
If you haven’t already done so, please, open the scratch program on your computer.
We create a variable in the “Variables” block section by clicking on “Make a variable”. For now we want to make
the variable “For this sprite only”, so make sure you select that button as below:
Click Ok. Notice that a new set of block is displayed on the blocks palette. One of them is named Score.
Once the variable is created you can us it in scripts to hold the value of a score in for example, the pong game
The checkbox to show/hide a variable.
In Scratch, there is also an option that allows users to decide to either show or hide a variable in stage. This option can be found in variable panel or by right-clicking the variable and selecting "hide".
Users may wish to change how a variable appears in program. A variables look can be changed to either:
"The normal readout";
or the "large readout".
To effect a change in the variables appearance, users need to double-clicking or right-clicking the variable and then select an option from the three given; or simply clicking it using the grow/shrink sprite tool.
Scratch Wiki, 2013. Scratch User Interface. [online]. Available from: http://wiki.scratch.mit.edu/wiki/Variable [Accessed 22 July 2013]
Note that the the Stage can only have global variables and not local variables.
According to the Scratch Wiki, two types of variables exist in Scratch 1.4; public (global), and private (local).
This is the default state of variables created in Scratch. When you initially create a variable, it is saved as global variable which means that it can be read and changed by any other sprite in the program.
Local variable are variables that can be read or modified by only specific sprites in a Scratch program. The process for creating local variables is similar to that of global. However, you make them local or private by selecting the option "For this sprite only." Selecting this option will make it possible for only the owner of the variables to change its attributes. For other sprites to read a local variable, they must use the () of () block, like the "delete 1 of list" shown in this image:
Local variables are very important. To illustrate, in a game of Ping Pong, where the individual scores of two different players need too be maintained, a variable called Score1 can be made local for player 1, and another called Score2 can be made local for player 2. These variables will then be programmed to hold the individual scores of each player.