LOW RESOLUTION
Animated GFA Input
BY ALBERT BAGGETTA
In the movie Short Circuit, we hear the robot, No. 5, frantically calling for more input, a word very important to us programmers because the user has to have some way of communicating with the machine. No. 5 was able to communicate through voice input, along with a myriad of sensory inputs (sophisticated, indeed), but our home computers are still a long way from behaving in this manner, so we input mainly through the keyboard.
I'm not knocking the mouse, mind you, because I think it is a fast way of communicating with the machine on a symbolic level—click on the icon, and presto! You get a reaction. But when it comes to entering long strings of text into our home computers, the keyboard is still the most expedient peripheral.
I program most of my games for the Atari ST in GFA BASIC because its interpreter is easy to use and the source code can be compiled to a very fast .PRG file. GFA has a good selection of input routines, but I found that there was something else I needed. The built-in input procedures of GFA work in one of the following ways: either you enter a complete string or a single character. While you enter the string, all other activity of the program freezes. Hit Return and the program resumes its activities—useful, but boring, especially for the game programmer.
Single-character input can allow screen activity to continue but restricts the amount of input allowed. The program can be made to check for a certain key press, but once that key is pressed the program is back about its business. One character is not usually enough, unless you're working off a menu.
Suppose you want to enter a string of characters—a person's name, a guess at a question, an item for a list—and still want some activity on the screen simultaneously—some sort of animation, for example. It is possible and not very difficult to accomplish if you do some planning and use some imagination.
I was confronted with just such a dilemma while writing a game program recently. I wanted the user to be able to enter a response to a question, but at the same time I wanted a pulsating border around the input area. The accompanying routines show some of the code I used to accomplish this, and it can easily be adapted for other uses.
Listing 1 is a low resolution, demonstration GFA program I have written to show how you may enter some short input (as described above) while screen activity continues. When you run the program, you will see a border of asterisks surrounding the prompt "Enter Your Name:" Type your name (no more than 15 characters are allowed here), and then press Return to have the name string printed below the border. You will notice that while you are typing your name, the border animation continues without interruption.
If you study Listing 1, you will see that the first part of the program creates the animated sequence while the computer checks for the string value entered into X$. The Inkey$ routine of GFA is used for this fast check. The source code section marked INPUT EXAMINATION is used to handle the input. First we check to see if the key pressed is "legal" before we show its character on the screen. (Everything is legal at this point except the Return key and the Backspace key. These will not print; they will result in an action. All other keys will be accepted and printed on the screen.)
One of the problems I had with this routine was allowing the correction of errors. Out of frustration, I resorted to the easiest method: instead of using Backspace to correct one character at a time, I have it erase the entire line, making the user start over again. This is not the best way to handle the editing, but since the required input is short, no great burden is placed on the user.
The whole input sequence and animation is placed within a REPEAT/UNTIL loop. When X$ becomes equal to a Return, or you have used up the allotted 15 characters, the routine ends, and your string is printed. In an actual program, you might print the resulting string, but more likely the string (called Name$, here) will be used to check for a correct answer or possibly might be used as part of a list.
The animation I created was done with the normal ASCII characters, but any kind of graphic or character animation can be incorporated in the loop. Because of GFA's tremendous speed, it takes quite a bit of screen activity before any hesitation appears in the actual input or animation.
I have put a delay loop at the end of the program, which is used during animation to slow down the speed of the flashing asterisk. If you play with the value in the delay loop, you can see how the movement is affected on screen.
Feel free to use this routine and modify it any way necessary. And let's see more animated input in the GFA programs you produce.
Albert Baggetta is an English teacher and a professional guitarist. He lives in Agawam, Massachusetts, with his wife, Beverly, and his two children. He frequently can be found wandering the ST-LOG SIG on DELPHI.