Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
strings and binary format?
#1
when i attempt to save my map on my map editor as binary, it seems to work. then when i attempt to open it and read it, it seems to work fine until it starts to pull in string variables. it brings in nothing for a string variable then everything after that is crazy. anything i can do?
Jumping Jahoolipers!
Reply
#2
You have to use fixed length strings;

Code:
GET #1,,stri$

Will read LEN(stri$) bytes, if stri$ is empty it will read nothing.
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#3
Code:
stri$=SPACE$(32)
GET #1, , stri$
Will read 32 bytes.

Code:
num=16
stri$=SPACE$(num)
GET #1, , stri$
Will read num (16) bytes.
Reply
#4
Whenever I need to put variable-length strings into a binary file, I first store the length of the string as an integer value and then the string. Reading it back in is also easy; you have a dynamic string variable set to read the data...you read the size of the string, SPACE the dynamic string variable to the size indicated, then read the string using your dynamic string variable. Works every time. Big Grin

Code:
DIM stringSize AS INTEGER
stringSize = LEN(outString$)
PUT #fh, , stringSize
PUT #fh, , outString$

...

GET #fh, , stringSize
inString$ = SPACE$(stringSize)
GET #fh, , inString$
I'd knock on wood, but my desk is particle board.
Reply
#5
i see... now i get it. thanks!

::EDIT::

it works like a charm! the files are approx. 2.5 times smaller than they were before. thanks!
Jumping Jahoolipers!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)