Subject: | |
From: | |
Reply To: | |
Date: | Fri, 4 Jun 1999 10:25:48 -0700 |
Content-Type: | text/plain |
Parts/Attachments: |
|
|
Mark asks:
> I'm writing a text-adventure in Cobol on a 3k. What I need to do is
> something like BASIC's INKEY function; I want to check if any keyboard input
> has happened and possibly do other processing.
>
> I *think* I need to open a file to $STDIN and set a quick timeout using
> FCONTROL; am I on the right track?
I don't think the the timeout-FREAD will work as you want it to.
I haven't tried it, but I think what you'll see is that anything entered
between the start of the FREAD and the timeout will be lost if the
timeout occurs before <return> is pressed.
I'd try one of three approaches:
1) typeahead & timeout-FREAD
By setting HPTYPEAHEAD to true, you enable typeahead (at least for
the session's $stdin ... but probably not for any other terminal
your program may have opened, if any)
Then, I'd try short reads with a timeout.
But...*TEST* it before you commit to this structure!
(And this approach still has problems!)
2) no wait IO
You can do No Wait I/O to the terminal, where you issue a read
and then go off and do something. Later, you call IODONTWAIT to
see if the read has completed (in which case you now have a buffer
of input data ... and you issue another READ eventually).
Note: this requires the user of privileged mode code (CAP=PM),
sadly.
(You may want to enable HPTYPEAHEAD too)
3) two-process architecture
The foreground process simply sits in a loop:
prompt user
read input (possibly with a timeout)
send input to server process (by writing to a message file)
get output from server process, display to user
The server process would be the main game program, and it would
be reading input from a message file ... input that would come from
any of the player processes.
(You may want to enable HPTYPEAHEAD too)
My favorite is #3.
--
Stan Sieler [log in to unmask]
http://www.allegro.com/sieler.html
|
|
|