On Wed, 13 Oct 2004, Benjamin Valentin wrote:
> I thought about saving the control settings of my little games in a
> control.txt file.
> Well, it works with all keys exept the ones whiches ASCII code contains
> something like chr$(0)+...
> So, here is the problem:
[can't read back strings with ASCII 0 bytes]
[snip]
A possibly stupid idea...[1]
If the key codes are all within ASCII range or have a leading character 0
for extended codes, try saving the keys as numbers, adding 1000 (a nice
round number that makes it easy to see what the second byte is) for
two-character key codes that begin with character 0. CHR$(0) + CHR$(53)
would be stored as 1053 for example. Then convert them back on input.
(Add appropriate "END IF"s if your version of BASIC requires it.)
> OPEN "control.txt" FOR INPUT AS #1
> INPUT #1, up$
[snip other keys]
> CLOSE
OPEN "control.txt" FOR INPUT AS #1
INPUT #1, up
IF up >999 THEN up$ = CHR$(0) + CHR$(up-1000) ELSE up$ = CHR$(up)
...
CLOSE
[snip]
> OPEN "control.txt" FOR OUTPUT AS #1
> WRITE #1, up$
[snip other keys]
> CLOSE
[snip]
OPEN "control.txt" FOR OUTPUT AS #1
up = ASC(up$): IF up = 0 THEN up = 1000 + ASC(RIGHT$(up$,1)
WRITE #1, up
...
CLOSE
Also, one WRITE statement could write all entries in one line and
one INPUT statement could read all of them at the same time. This
could save a few lines of code.
[1] BTNSMB
--
Norman De Forest
http://www.chebucto.ns.ca/~af380/Profile.html
af380@chebucto.ns.ca [=||=] (A Speech Friendly Site)
"O'Reilly is to a system administrator as a shoulder length latex glove
is to a veterinarian." -- Peter da Silva in the scary devil monastery