Apr 14, 2013 at 4:55am
Here is my SetTiles function for loading maps in my game.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
int Map::SetTiles(char* mapfile)
{
int X;
int Y;
std::ifstream Map/*(mapfile, NULL)*/;
Map.open(mapfile, NULL);
if(Map == NULL)
{
printf("Map failed to load : cannot open map.\n");
return 1;
}
for(int t = 0; t < MaxTiles; t++)
{
int tiletype = -1;
Map >> tiletype;
if(Map.fail() == true)
{
printf("Map failed to load : failed to get tile type\n");
Map.close();
return 1;
}
if((tiletype >= 0) && (tiletype < TILETYPES))
{
Tiles[t] = new Tile( X, Y, tiletype );
}
else
{
printf("Map failed to load\n");
Map.close();
return 1;
}
X += 32;
if(X >= LevelW)
{
X = 0;
Y += 32;
}
}
printf("Map successfully loaded\n");
return 0;
}
|
The problem is here. I've narrowed the problem down to these lines(Thanks to error messages):
1 2
|
std::ifstream Map/*(mapfile, NULL)*/;
Map.open(mapfile, NULL);
|
No matter what, it fails to load the map file.
All help is appreciated, I've done this before, I cannot figure out the problem.
Last edited on Apr 14, 2013 at 4:55am by Fredbill30
Apr 14, 2013 at 5:40am
Why are you passing NULL to ifstream::open()?
Edit: Doesn't really matter I was just curious. Are you sure mapfile is the correct file path?
Last edited on Apr 14, 2013 at 6:18am
Apr 14, 2013 at 3:29pm
I feel like an idiot. It was the wrong path lol.