I'm still inexperienced with C++. I am trying to load game entities and their xyz coordinates from a text file "1.ent" I thought it would be a good idea for a map format.
here is the MyMap.cpp:
here is the text file:Code:#include "CEntity.h" #include "MyMap.h" CEntity* MyMap::GetEntity(std::string type ) { if( type == "player" ) return new CPlayer(/*you can stick parameters for the constructor in here*/); if( type == "entity" ) return new CEntity(); /*if( type == "cactus" ) return new Cactus(); */ // And so on, ad infinitum. } bool MyMap::LoadMap(char* File) { FILE* FileHandle = fopen(File, "r"); if(FileHandle == NULL) { return false; } fscanf(FileHandle, "%i\n", map_size); //read size from the first line of the file. obj_array = new CEntity[map_size]; char read_type[255]; std::string type; float xval; float yval; float zval; for (int i=0;i<=(map_size-1);i++) { //type = first string per Entity //xval = second string //yval = third string //zval = fourth string fscanf(FileHandle, "%s\n", read_type); fscanf(FileHandle, "%f\n", xval); fscanf(FileHandle, "%f\n", yval); fscanf(FileHandle, "%f\n", zval); type = read_type; //have a special string called "end" at the end of the map file. if (type != "end") { if ((obj_array[i] = GetEntity(type)) != NULL) { //by this point the constructor on the new object is already called. //but we won't use the constructor we will set the values directly. obj_array[i].X = xval; obj_array[i].Y = yval; //obj_array[i].z = zval; //switch this to a list specific to this map when you expand the engine. CEntity::EntityList.push_back(obj_array[i]); } } else break; } } void MyMap::OnCleanUp() { //not sure if this part is necessary for (int i=0;i<=(map_size-1);i++) { if (obj_array[i] != Null) delete obj_array[i]; } //considering I have this delete [] obj_array; }
When I compile I get a big error on this line:Code:3 player 400.0 40.0 0.0 player 500.0 40.0 0.0 player 600.0 0.0 0.0 end:0:0:0
here it is:Code:[if ((obj_array[i] = GetEntity(type)) != NULL)]
anyone know how to fix this?Code:error: C:\Projects\2D_Engine\MyMap.cpp|54|error: no match for 'operator=' in '*(((MyMap*)this)->MyMap::obj_array + ((unsigned int)(((unsigned int)i) * 116u))) = MyMap::GetEntity(std::basic_string<char>(((const std::basic_string<char>&)((const std::basic_string<char>*)(& type)))))'| note: C:\Projects\2D_Engine\CEntity.h|30|note: candidate is: CEntity& CEntity::operator=(const CEntity&)|
thanks,




Reply With Quote
