Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: MachineElf on Tue 15/07/2003 21:41:25

Title: File I/O
Post by: MachineElf on Tue 15/07/2003 21:41:25
Can anyone explain to me how the File I/O in AGS really work?
There seem to be no way of reading a specific line in a file or even reading more than one thing from a file, or am I getting this all wrong?

An examle: Say I have a file called bice.dat that looks something like this (I guess the file format looks somewhat different but never mind for now):

"This is a string
5 10
15
-- EOF --"

Now I'd like to read the first line into a string and the numbers into three different integers. Would this be possible in any way? And how do I make a file that actually look like this?

If anyone wonders I'm once again trying to expand the limits of AGS a little, this time by making a little play-by-email game...
Title: Re:File I/O
Post by: Scorpiorus on Tue 15/07/2003 22:08:13
ok, making such a file.....

int file = FileOpen("bice.dat", FILE_WRITE);
if (file == 0) { Display("error creating a file"); QuitGame(0); }
else {
FileWrite(file, "This is a string");
FileWriteInt(file, 5);
FileWriteInt(file, 10);
FileWriteInt(file, 15);
FileClose(file);
}


reading from file...
string string_buffer;
int value1, value2, value3;

int file = FileOpen("bice.dat", FILE_READ);
if (file == 0) { Display("error opening file"); QuitGame(0); }
else {
FileRead(file, string_buffer);
//a little correction here
value1 = FileReadInt(file);
value2 = FileReadInt(file);
value3 = FileReadInt(file);

FileClose(file);
}


but keep in mind that these functions write data in the special AGS format.

-Cheers
Title: Re:File I/O
Post by: MachineElf on Tue 15/07/2003 22:24:43
Ah, yes of course. The "cursor" moves in the file when reading and writing, just like in C.

Well, thanks!

Is there anyway to perform a command that lists all .dat-files (or just all files) in the game directory? I can't seem to find any function for this.
Title: Re:File I/O
Post by: Scorpiorus on Tue 15/07/2003 22:40:33
QuoteAh, yes of course. The "cursor" moves in the file when reading and writing, just like in C.
aha, exactly.

QuoteIs there anyway to perform a command that lists all .dat-files (or just all files) in the game directory? I can't seem to find any function for this.
there is no such one in files section but you can look at ListBoxDirList() function. You need to create a listbox then and retrieve the files names via ListBoxGetItemText() command. ;)

-Cheers
Title: Re:File I/O
Post by: MachineElf on Tue 15/07/2003 22:47:00
Yeah, that does it! Thanks a lot!