<< Chapter < Page Chapter >> Page >

Image 3. programming blocks in the events category.

Missing image.
Image 3. Programming blocks in the Events category.

The finished program

The rightmost panel in Image 1 shows the finished program. I created the program by dragging blocks fromthe Data toolbox and the Events toolbox and snapping them together to form three separatescripts.

(Actually the program that you see in Image 1 is the result of an automatic conversion from v1.4 to v2.0 that was performed by the folks at MIT during the transition period fromv1.4 to v2.0. I originally wrote that program in v1.4. Some of the toolboxes had different names in v1.4.)

Note that I also entered literal values of 0, 1, 5, -1, and -5 into the white text fields in the programming blocks for the variables after dragging them intothe programming area.

In addition, I used the pull-down list on each of six orange Data blocks in Image 1 to select the name of the variable to which that block applies. (Note that each of those six blocks refers either to Counter or counter .)

Behavior of the program

Click the green flag

The program contains three scripts. Each script remains silent until a specific event occurs. As the label on the uppermostblock in the top programming script in Image 1 indicates, the code in the top script in Image 1 is executed once each time the user clicks the green flag shown in the upper right ofthe stage. This code causes the values stored in each of the two variables to be set to zero. This, in turn causes thevariable displays in the Stage area to each show a value of 0.

Press the space bar

Because of the top block in the middle script reads "when space key pressed" , the code in the middle script is executed once each time the user presses the space bar.

The pull-down list on this block allows you to select among the keys on the keyboard with the space bar being the default.

One of the orange programming blocks in the middle script causes the value of the variable named Counter to change by +1 when the space bar is pressed. The other orangeprogramming block causes the value of the variable named counter to change by +5 when the space bar is pressed.

In other words, repetitively pressing the space bar causes the Counter variable to count up in increments of one and causes the counter variable to count up in increments of five.

Click the mouse on the Stage

Because of the top block in the bottom script reads "when this spriteclicked" , the code in the bottom script in Image 1 is executed once each time the user clicks the mouse in the large white Stagearea shown in Image 1 .

(In this case, there are no sprites so this event is triggered by clicking the stage. I believe this isa new label on this block in v2.0. This label, which refers to a sprite, seems to be a little too specific.)

The bottom two blocks in this script are the same as the bottom two blocks in the middle script except that the algebraic signs on the two literal values are minus instead of plus.

The absence of a "-" character causes a literal value to be positive. A "+" character is notrequired for positive literal values.

Questions & Answers

what is phylogeny
Odigie Reply
evolutionary history and relationship of an organism or group of organisms
AI-Robot
ok
Deng
what is biology
Hajah Reply
the study of living organisms and their interactions with one another and their environments
AI-Robot
what is biology
Victoria Reply
HOW CAN MAN ORGAN FUNCTION
Alfred Reply
the diagram of the digestive system
Assiatu Reply
allimentary cannel
Ogenrwot
How does twins formed
William Reply
They formed in two ways first when one sperm and one egg are splited by mitosis or two sperm and two eggs join together
Oluwatobi
what is genetics
Josephine Reply
Genetics is the study of heredity
Misack
how does twins formed?
Misack
What is manual
Hassan Reply
discuss biological phenomenon and provide pieces of evidence to show that it was responsible for the formation of eukaryotic organelles
Joseph Reply
what is biology
Yousuf Reply
the study of living organisms and their interactions with one another and their environment.
Wine
discuss the biological phenomenon and provide pieces of evidence to show that it was responsible for the formation of eukaryotic organelles in an essay form
Joseph Reply
what is the blood cells
Shaker Reply
list any five characteristics of the blood cells
Shaker
lack electricity and its more savely than electronic microscope because its naturally by using of light
Abdullahi Reply
advantage of electronic microscope is easily and clearly while disadvantage is dangerous because its electronic. advantage of light microscope is savely and naturally by sun while disadvantage is not easily,means its not sharp and not clear
Abdullahi
cell theory state that every organisms composed of one or more cell,cell is the basic unit of life
Abdullahi
is like gone fail us
DENG
cells is the basic structure and functions of all living things
Ramadan
What is classification
ISCONT Reply
is organisms that are similar into groups called tara
Yamosa
in what situation (s) would be the use of a scanning electron microscope be ideal and why?
Kenna Reply
A scanning electron microscope (SEM) is ideal for situations requiring high-resolution imaging of surfaces. It is commonly used in materials science, biology, and geology to examine the topography and composition of samples at a nanoscale level. SEM is particularly useful for studying fine details,
Hilary
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Teaching beginners to code. OpenStax CNX. May 27, 2013 Download for free at http://cnx.org/content/col11498/1.20
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Teaching beginners to code' conversation and receive update notifications?

Ask