Hi everyone, i just wanted to contribute a little to everyone here. Yesterday i was checking my code to make it better and more understandable and all that, and i remember a lot of people having trouble with Dark GDKs integrated file functions. Contrary of what you may think, the Dark GDK In Built file system is not "crap" or "crappy" or whatever. Yes i know you can use fstream. people just dont know how it works. ive made a simple code to read a file, compare some strings and set some resolution/media folder settings. i will explain the code below:
char *ConfigFileReader;
char *CheckConfigFileLine;
dbOpenToRead(1, "config.txt");
if(!dbFileOpen(1) || dbFileEnd(1))// Setup default settings if the config file is not found or is empty
{
resx=800;
resy=600;
resdepth=32;
MediaFolder="Media";
}
else// Config file was found, proceed and read it
{
for(char *ConfigFileLine=dbReadString(1);dbFileEnd(1) != 1;ConfigFileLine= dbReadString(1)) // read first line, keep reading lines and storing them in ConfigFileLine until the end of file is reached.
{
CheckConfigFileLine = dbFirstToken(ConfigFileLine,"=");
if(CheckConfigFileLine != NULL)
{
if(strncmp(CheckConfigFileLine, "Resx",32) == 0) {CheckConfigFileLine=dbNextToken("=");resx = atoi(CheckConfigFileLine);}
if(strcmp(CheckConfigFileLine, "Resy") == 0) {CheckConfigFileLine=dbNextToken("=");resy = atoi(CheckConfigFileLine);}
if(strcmp(CheckConfigFileLine, "ResDepth") == 0) {CheckConfigFileLine=dbNextToken("=");resdepth = atoi(CheckConfigFileLine);}
if(strcmp(CheckConfigFileLine, "Fullscreen") == 0) {CheckConfigFileLine=dbNextToken("=");Fullscreen = atoi(CheckConfigFileLine);}
if(strcmp(CheckConfigFileLine, "MediaFolder") == 0) {CheckConfigFileLine=dbNextToken("=");MediaFolder = CheckConfigFileLine;}
}
}
dbCloseFile(1);
}
dbSetDisplayMode (resx ,resy ,resdepth );
if (Fullscreen==1){ dbMaximiseWindow( );dbSetWindowOff( );}
else{dbSetWindowPosition(50,50);}
dbSetDir ( MediaFolder );
first of all, declare some variables to work with.
next, call the dbOpenToRead command. this is obvious.
then check if the file was opened, or if it is empty, and set the default variables if no file is found, here, you can implement a file maker, which maybe ill discuss later in this same thread.
next, if the file is open, start by reading the first line, and tokenizing it, or " separating it" where a "=" is found with dbFirstToken. then compare the string you have using strncmp or strcmp, the only difference between those two is that in one you specify the number of letters or characters to compare. you can see it in the code.
Then, if comparing succeeds, say, at ResX, then use dbNextToken("="); to read what is next to ResX=. then convert it to whatever you need it, i used atoi to convert it to Int, and store it wherever you want. i used int resx. just add more ifs to compare the string to whatever you want.
when the end of file is reached, close the file. this code goes before the main loop. Oh! i almost forgot, i think this is only for version 7.4, since i dont remember having the tokenizer system integrated in Dark. i know this may not be the best place to post this but i know more people starting will read it here.
this is just some part of the code im using, as simple as it can get. i really hope this helps a lot of people as i know there are people who have asked for it.. well i investigated, tested and here it is for all of those who want to put it in your Apps, Games or program. hope i get into your game credits
hi