I have a problem with reading external files.
Writing to files works great but if I want to read from files it only works once and only if I call my function directly from G_InitGame().
Here is a snippet of the code I use:
qboolean readFromFile() {
char FILE_NAME[MAX_QPATH];
fileHandle_t file;
int len;
sprintf(FILE_NAME, "%s.file", level.rawmapname);
len = trap_FS_FOpenFile(FILE_NAME, &file, FS_READ);
if (len <= 0) {
G_Printf(S_COLOR_RED "File %s empty.
", FILE_NAME);
return qfalse;
}
// here follows reading and parsing stuff
[...]
trap_FS_FCloseFile(file);
return qtrue;
}
I call my function from G_InitGame():
void G_InitGame( int levelTime, int randomSeed, int restart ) {
[...]
readFromFile();
}
The thing I don’t undestand is:
If the function is called for the first time (during warmup init) it works great but after that it always reports an empty file.
For testing I added a server command to manually call the function and removed the call from G_Init but that way it didn’t even work on the first call.
I write to files in several other places of my code and writing works everytime.
I really hope someone here can help me or at least give me a hint.
