I am creating a map editor and trying to open a file to write down the map data but my folder doesn't show any file after I closed my application. I read the documentation of "OpenToWrite" and it describes :
->Opens a file stored on the local filesystem for writing into the specified ID. and
->If the file does not exist it will be created
In my understanding, the command will create a file if the file doesn't exist but it didn't work for me. Below is the code.
By the way I coded in C++.
// Includes
#include "template.h"
// Namespace
using namespace AGK;
app App;
//global variables
struct Map {
int type;
};
Map map[16][12];
int pX, pY;
int currentType;
int BLUE = agk::MakeColor(0, 0, 255);
int GREEN = agk::MakeColor(0, 255, 0);
int file;
void app::Begin(void)
{
agk::SetVirtualResolution (1024, 768);
agk::SetClearColor( 0,0,0 ); // dark
agk::SetSyncRate(30,0);
agk::SetScissor(0,0,0,0);
//Initialize map
for (int i = 0; i < 16; i++) {
for (int j = 0; j < 12; j++) {
map[i][j].type = 0;
}
}
currentType = 0;
agk::OpenToWrite(1, "test.txt", 0);
}
int app::Loop (void)
{
int mouseX = agk::GetPointerX();
int mouseY = agk::GetPointerY();
if (agk::GetPointerPressed() == 1) {
pX = mouseX;
pY = mouseY;
}
if (agk::GetRawKeyPressed(39)) {
currentType++;
if (currentType > 3) {
currentType = 0;
}
}
else if (agk::GetRawKeyPressed(37)) {
currentType--;
if (currentType < 0) {
currentType = 3;
}
}
agk::Print(pX);
agk::Print(pY);
agk::Print(currentType);
for (int i = 0; i < 16; i++) {
for (int j = 0; j < 12; j++) {
if (map[i][j].type == 0) {
agk::DrawBox(i * 64, j * 64, i * 64 + 64, j * 64 + 64, 255, 255, 255, 255, 0);
}
if (map[i][j].type == 1) {
agk::DrawBox(i * 64, j * 64, i * 64 + 64, j * 64 + 64, 255, 255, 255, 255, 1);
}
if (map[i][j].type == 2) {
agk::DrawBox(i * 64, j * 64, i * 64 + 64, j * 64 + 64, BLUE, BLUE, BLUE, BLUE, 1);
}
if (map[i][j].type == 3) {
agk::DrawBox(i * 64, j * 64, i * 64 + 64, j * 64 + 64, GREEN, GREEN, GREEN, GREEN, 1);
}
if (pX >= 64 * i && pX < 64 * (i + 1) && pY >= 64 * j && pY < 64 * (j + 1) && (agk::GetPointerPressed()==1)) {
agk::Print("clicked");
map[i][j].type = currentType;
}
}
}
agk::Sync();
if (agk::FileIsOpen(1) == 1) {
for (int i = 0; i < 16; i++) {
for (int j = 0; j < 12; j++) {
agk::WriteInteger(1, map[i][j].type);
agk::Print("kajsd");
}
}
}
agk::CloseFile(1);
return 0; // return 1 to close app
}
void app::End (void)
{
}
I was wondering if I put the code in the wrong way, or maybe just the folder path problem?