189
Chapter 5 Collision Theory and Logic
Persistence
means that something continues to exist after the event that
caused it has ended. If you have your picture taken with a flash and see spots,
you have persistence of vision from the flash. Likewise, you do not have to
memorize the definition of each word you use each time you use it. You use the
same words every day to mean the same thing. This is not true of a computer.
A computer does not remember a definition from one program to another. For
a computer, the name of a function, subroutine, variable, and so on, must be
declared.
Declared
means that the item is given a name and use in the program
you are writing. Therefore, use names that make sense. Use common syntax
you already know to easily understand the language you are using.
There is a way for the computer to recall subroutines and variables from one
module to another.
Modules
are separate units of programming that perform one
function and contain all of the information needed to execute that function. A
subroutine or variable can be classified as global or local to a module.
A
global
subroutine or variable works everywhere in the program that
you are writing. Global subroutines can be declared by a programmer if the
subroutine needs to work inside the current module and also in another module.
If you define a global subroutine for level 1 of the game, it can be recalled in
level 2. In this way, global subroutines have persistence between modules.
A
local
subroutine or variable does not have persistence outside of the
module in which it was declared. If you use a local subroutine on level 1 of the
game, the computer will “forget” what it means in level 2. This allows you to
use an object called
Ball
in different levels and have that ball be unique on each
level. An example in your class might be using the name Joe for a student in
your computer class. Using just the first name of Joe as a local variable works
well in the module of your computer class because there is only one student
declared with the name Joe. However, Joe does not work well as a global
declaration because there are many students with the name Joe at school. A
global declaration for the same student might best be done using the first and
last name, like Joe Phillips, so he can be identified throughout the school.
Objects should also be named to add information about the use and type.
Programmers should avoid just numbering things. It is very difficult to debug
a program with 60 objects called
Object
1,
Object
2,
Object
3…Object 60. It
is much easier to debug if you have descriptive names such as objCat_Red,
objCat_Yellow, objDog_Black,…objWall_Brick. This keeps you from having to read
the properties of each object to find out which one is the black dog.
Green Gamer
Paper manufactures are always looking for renewable
resources and new ideas to produce environmentally
friendly paper products. One ecofriendly paper is made
from byproducts of sugarcane with no wood involved in
its production. Sugarcane products actually biodegrade
faster than wood products and sugarcane paper is cleaner to make than
wood-based paper. When purchasing video games, look for companies that
use sugarcane paper in the packaging materials.
Previous Page Next Page