Hi, Im currently working on a game which needs to save certain stats to a file as a kind of save function, I know you can use the C++ file input and output, but to be honest, Im a epic nub at the moment when it comes to coding...
What Im asking is:
- How do I call a function from C++ so that it would save the data from the string in DarkGDK
- How do I get the data from the file back into DarkGDK
- And finally how do I create files/directorys in C++ (Or should I just do that in DarkGDK?
Here is my current code that ive been working on but whenever I try to pull the data from the file it seems to come up with some random characters
#include "DarkGDK.h"
void DarkGDK ( void )
{
dbSyncOn ( );
dbSyncRate ( 10 );
dbSetImageColorKey ( 255, 0, 255 );
dbMakeDirectory("DirectoryTest");
dbSetDir("DirectoryTest");
char CData[100];
char WData[100];
while ( LoopGDK ( ) )
{
//CREATE
if (dbLeftKey())
{
if ( dbFileExist( "Data.txt" ) )
{
dbText(10,10, "File already exists");
}
else
{
dbMakeFile("Data.txt");
dbText(10,10, "File 'Data.txt' now exists");
}
}
//WRITE
if (dbUpKey())
{
if ( dbFileExist( "Data.txt" ) )
{
dbPrint("Enter some characters: ");
strcpy(WData, dbInput());
dbOpenToWrite(1, "Data.txt");
dbWriteString(1, WData);
dbCloseFile(1);
dbText(10,10,"Data has been written onto file");
}
else
{
dbText(10,10,"File does not exist");
}
}
//READ
if (dbRightKey())
{
if ( dbFileExist( "Data.txt" ) )
{
dbOpenToRead(1, "Data.txt");
dbReadString(1, CData);
dbCloseFile(1);
dbText(10,10,CData);
}
else
{
dbText(10,10,"File does not exist");
}
}
//CLEAR SCREEN
if (dbDownKey())
dbCLS();
dbSync ( );
}
return;
}