Contents of the BAS-PLAY.TXT file
USING BASICA/GWBASIC'S "PLAY" COMMAND
TO CONTROL PROGRAM TIMING.
When you are writing a program of any kind, you
often need to add pauses to allow the user to read
screens or just to make the program move at the pace
Traditionally, these pauses are created using an
empty loop. A typical pause routine might look like
10 FOR X=1 TO 100
20 NEXT X
That's all right, but it takes two separate
statements, and requires you to figure out just how
long those 100 clock ticks will take. There is a
much simpler method of creating pauses in your
program--one which requires only one statement. It
is also much easier to use.
The "PLAY" command, as implemented in BASICA and
GWBASIC, is designed primarily to add music to your
programs, but one of its statements can be used to
pause as well. Since music incorporates rests as
well as notes, "PLAY" includes a way to control
musical rests. You can use these as timing
"PLAY" uses string statements to play music and to
generate rests or silent periods. A typical command
might look like this:
10 PLAY "P1"
Whenever this statement appears in a program, BASICA
tells the computer to [P]ause for 2 seconds. The
number in the string tells the program to [P]ause
for a musical whole note. If the statement had been
"P2," the program would have [P]aused for 1 second.
Here is a list of the possibilities:
Statement Length of pause
"P1" 2.0 sec.
"P2" 1.0 sec.
"P4" .5 sec.
"P8" .25 sec
"P16" .125 sec.
"P32" .0625 sec.
"P64" .03125 sec.
It's easy to remember if you think of the numbers as
reciprocals, with 1 equal to 2 seconds. There is
more, however. You can string pauses together to
add additional time. If you wanted a four-second
pause, the statement would be: PLAY "P1P1". How
about 1.5 seconds? Just write PLAY "P2P4." The
precision you can create is amazing, and the process
is much simpler than using loops.
But that's not all! You can control the length of
each pause by making a [T]empo statement, which
alters all the remaining statements. BASICA's
default tempo is 120 beats per minute. The "4"
figure is the one which gets the beat, so you can
see where the .5 second pause in the chart
To make the "P4" statement [P]ause for a full
second, make the statement this way: PLAY "T60P1".
The [T]empo statement resets the number of beats per
minute to 60. All the remaining numbers used will
reflect the new [T]empo. The range you can use in
[T]empo statements is from 32 to 255 beats per
Finally, the [T]empo statement you make in the first
"PLAY" command becomes the new default, and remains
the same through any later "PLAY" commands until you
change it. You can use this feature by setting the
[T]empo early in the program. Then, to change the
speed of the entire program, just change the [T]empo
in the first statement.