>> MapFile >> buffer;
what does this line do?
>> MapFile >> buffer;
what does this line do?
it put the buffer into map...
oh
may be that is the problem
you should try these
strcpy(reinterpret_cast<char *>Map,reinterpret_cast<char *> buffer)
or do a memcpy() it is lot faster
sorry i read it wrong
it read the file in buffer
>> it read the file in buffer
So how's buffer supposed to change?
didn't I say I am using fstream?
and all this does the same exact thing. what I cannot understand is why the textprintf() that prints out the variable type works in the loop that assigns the values to all the type variables, but when I do it outside of there, it always gives me zero.
> for (int i=0; i <= height; i++)
What are the values of width and height?
And why isn't it
for (int i=0; i < height; i++)
Perhaps you're stepping off the end of the array
Sebastani, your method made it say "The value is indeed zero" and the %g had the same results as well.
Anyone want to look at the code at a whole and figure this out? My uncle couldn't figure this out either, and he is a professional C++ programmer.
width is 60 and height is 45.
and what is weird is if I don't make it <= it loops forever.
what the heck? the height and width are read from an external file, and if I change the width and height in the file to 59 and 44, it loops forever as well.
> width is 60 and height is 45.
Well this definitely steps off the end of the array big time
Perhaps you have too much data in your file, like one extra row or column of tile data?
> Anyone want to look at the code at a whole and figure this out?
If you can reduce it to a test case which doesn't require external libraries (plain ANSI-C++ which everyone can compile), then zip it up with an input file and attach it.
how is that stepping over? I got a 60 by 45 by 3 array for the tiles, and the map is 60 by 45 by 1!
Does the file solely consist of integers? Does it just contain the type or the whole tile? Can you post your whole loadfile function and a sample of the file?
sure.
now don't tell me about how messy it is, because I haven't had a chance to clean it up.
now the textprintf() in there as I said b4 displays the number perfectly, but if I try to do the same thing outside of the LoadMap() function, it always gives me 0.Code:void map::LoadMap(char *FileToLoad) { MapFileName = FileToLoad; ExcludeSecondLayer = false; char buffer[256]; ifstream MapFile(FileToLoad); while (!MapFile.eof() && strcmp(buffer,"[INITIALIZATION]")) { MapFile >> buffer; } while (!MapFile.eof() && strcmp(buffer,"[TILES]")) { MapFile >> buffer; if (!strcmp(buffer,"WIDTH")) { MapFile >> buffer; width = atoi(buffer); } else if (!strcmp(buffer,"HEIGHT")) { MapFile >> buffer; height = atoi(buffer); } else if (!strcmp(buffer,"S_CAMX")) { MapFile >> buffer; camerax = atoi(buffer); } else if (!strcmp(buffer,"S_CAMY")) { MapFile >> buffer; cameray = atoi(buffer); } else if (!strcmp(buffer,"EX_LAYER2")) ExcludeSecondLayer = true; else if (!strcmp(buffer,"MAPNAME")) { MapFile.getline(buffer,256); MapName = buffer; } } while (!MapFile.eof() && strcmp(buffer,"ENDMAP")) { MapFile >> buffer; if (!strcmp(buffer,"LAYER1")) { MapFile >> buffer; int LoadPositionX = 0; int LoadPositionY = 0; for (int i=0; i <= width; i++) { for (int j=0; j <= height; j++) { MapFile >> buffer; clear(screen); tiles[LoadPositionX][LoadPositionY][0].type = atoi(buffer); textprintf(screen,font,0,0,makecol(255,255,255),"%d",tiles[LoadPositionX][LoadPositionY][0].type); LoadPositionX++; } LoadPositionX = 0; LoadPositionY++; } MapFile >> buffer; } } MapFile.close(); }
I attached the map file with this post. It is a supposed to be a .tmf file, but I don't know if it'll let me attach a .tmf file so I renamed it to .txt for attaching sake.