Chapter 5
Game
Controllers
165
have to wait for it.
If
you want to write
an
"action" program that receives
instructions from the keyboard, you can use the GET statement.
Like INPUT, the GET statement reads information from the keyboard.
But that's where the similarities end. The main differences are as follows:
1.
INPUT
reads one
or
more complete numbers
or
strings. GET reads
only a single keystroke.
2.
Using INPUT, the program waits for you to press RETURN.
If
nothing
is
typed, your program will wait indefinitely. GET, on the
other hand, never waits; if no key was pressed the program tells you
so, but keeps on running.
3.
When you are typing in response to
an
INPUT
statement, the "?"
prompts you for input,
and
the characters you type appear on the
screen. GET has no prompt and doesn't echo what you type.
In other words, with a GET statement a program can determine
whether a key has been pressed, but won't wait if no key
is
pressed.
If
the
person using the program types nothing, the program can determine this
and make decisions based on it.
GET
Statement
Syntax
The syntax
of
GET, shown in the following line,
is
quite simple:
GET
variable name
No options are available. You must have exactly one variable in the "list."
Unlike INPUT, no prompt string
is
allowed. You can, however, easily
display a prompt string:
Use
a
PRINT
statement terminated with a semi-
colon to stop the VIC from printing a
RETURN.
10
PRINT"THIS
IS
A
PROMPT:"i
20
GET
At
The variable used with GET can be any type (integer, floating point,
or
string), but a string variable works best. There are two reasons for this.
1.
If
a numeric variable
is
used, BASIC attempts to interpret any key
pressed as a number. If you type something other than a number, a
syntax error occurs and the program stops.