forums

TNT Basic Forums > Programming Q&A
Trouble with reading files
< Last Thread     Next Thread >
Author
Thread        Post A Reply

12-12-2001 02:37

Posted by:
Jim

Click Here to Email Jim   Find more posts by Jim

I'm having trouble using the File Read String command (or any of the file reading commands). It always reports that there is an "Unexpected end of file." Could you help me figure out what I'm doing wrong? Here is a simple sample program to illustrate what I'm having trouble doing:

--

Text Mode

int fp = Ask Open File( false, "TEXT" )

string s = File Read String ( fp )

Close File ( fp )

print s

--

It always gives an error on the File Read String line. I'm sure its something obvious, but I'd really appreciate some help anyways. Thanks.

12-12-2001 10:48

Posted by:
Mark Tully

Find more posts by Mark Tully

Binary files I'm afraid...

Are you trying to open a text file that you've created yourself?

TNT Basic currently only reads binary files written out by commands like "write file".

You could write a simple program which creates one of these files by writing out all your strings to a file. it would look something like:

int myfile=ask create file ("Test")
int count
str text

for count = 1 to 3
read text
file write myfile,text
next

close file myfile

data "String 1","String 2","String 3"


We'll add support for text files in a future version of TNT Basic, sorry about that!

Thanks for you interest!

12-12-2001 13:55

Posted by:
Jim

Click Here to Email Jim   Find more posts by Jim

OK, thanks. I should be able to write the files that way for the time being. (Although the ability to access regular text files will be nice.)

12-12-2001 15:53

Posted by:
Mark Tully

Find more posts by Mark Tully

Regular Text Files

Jim,

Can you tell me a bit more about how you envisage using text files, just so I can get an idea of what you need.

Thanks,

Mark

12-12-2001 16:23

Posted by:
Jim

Click Here to Email Jim   Find more posts by Jim

Well, I've realized that the existing commands are pretty good, but by regular text file I just meant the ability to open any old text file and read, say, a line or a character at a time. That way I could edit data manually with an editor like bbedit. I just think it would be convenient to be able to open text files as opposed to binary files (although I must admit I'm a little hazy about the difference between the two).

Another small addition that I think might be handy would be a 'Set Directory Application' command that sets the directory to the folder that the running program is in.

12-20-2001 19:27

Posted by:
Jon

Click Here to Email Jon   Find more posts by Jon

Re: Text Files

Well I'm not Tony, but I would like to be able to use text files. I would use them to hold character dialog, so that I could easily change it or translate to a different language.

Also, Is it possible to load maps/graphics from a file? I want to be able to have plug-in levels or power-ups. For instance, I could have a plugin with a new type of ship, but I would need to be able to hold the new graphics in that file.

Thanks,
Jon

12-21-2001 11:03

Posted by:
Mark Tully

Find more posts by Mark Tully

External Resource Files

Hi Jon,

If we take your idea all the way, what you basically want is a way to load up another TNT Basic project file and load the graphics/maps/sounds etc from it.

You can't currently do this in TNT Basic, but an update of the file commands are on to do list (which is pretty long I'm afraid, so don't hold your breath!)

Thanks for you interest,

Mark

All times are GMT        Post A Reply

Forum Jump:
< Last Thread     Next Thread >

< Contact Us - TNT Basic >

Powered by: vBulletin Lite Version 1.0.1 Lite
Copyright © Jelsoft Enterprises Limited 2000.