<< Chapter < Page | Chapter >> Page > |
Most programming languages have very specific requirements regarding the allowable characters for variable names. I suspect that this is also true ofScratch, but I haven't found that specification anywhere. You will probably be okay as long as you stick with letters, numbers, the underscore character"_", and the hyphen or minus sign "-".
It appears experimentally that the allowable length of the variable name is longer than you would ever want to use so length doesn't seem to be alimitation.
Many programming languages won't allow you to use a numeric character for the first character in a variable name, but that restriction doesn't seem to applyto Scratch. However, since you might later move up to more mainstream languages, you might want to avoid getting into the habit of using numeric characters asthe first character in variable names.
When using Scratch and all other programming languages, you should strive to use variable names that are meaningful. My preference is to begin variable nameswith a lower-case letter, use multiple words in the name where appropriate, and separate the words using a format commonly called camelCase to cause the human eye to separate the words.
(The upper-case characters are analogous to the humps on a camel.)
Here is an example of the camelCase format:
aVariableName
Some people prefer the following format:
A_Variable_Name
I prefer the camelCase format because it is easier to type, requires fewer characters, takes less space, and in my opinion, is just as effective.
Generally speaking, programs are written in Scratch by:
There are other steps involved in writing a complex program that I didn't include above, but we will get to them later in this collection of modules.Hopefully you already know the physical steps in writing a program as a result of working through some online tutorials.
Although Scratch 2.0 has some new features and a different screen layout, the general procedure for writing a program in Scratch 2.0 isessentially the same as the procedure for writing a program in Scratch 1.4. Thus, the older v1.4 tutorials are still very relevant.
As you can see in Image 1 , this program consists of three scripts in the rightmost pane. Each script contains onetan block and two orange blocks. We already know that orange blocks have to do with data or variables. As you can see from the colors on the left ends of the buttonsin Image 1 , tan blocks are related to Events .
Image 3 shows some of the programming blocks that are available in the Events category. (Scratch 1.4 had tools for the Events category and the Control category combined into a single toolbox.)
Notification Switch
Would you like to follow the 'Teaching beginners to code' conversation and receive update notifications?