Hey, I'm having a problem with my RPG. I'm trying to get a player to move from one room to another. All the coordinates (and other properties) of all the objects inside a given room are contained inside a text file, and this includes the properties of an exit to a different room. The exit has a position, sprite, and most importantly, a char* that holds the name of the script to look at to "build" the next room (obviously it isn't a char* inside the text file, my game just interprets it and stores it as a char*, which is a member of an Exit class). However, when it comes time to load the next room, the member that held the new room's filename is corrupt (not sure if that's the correct word - it basically no longer has the right data). I think there's an issue with how I store the filename.
else if(strcmp(buffer,"#exitNextRoomScript") == 0)
{
char next_room_script[MAX_PATH];
fscanf(file,"%s",next_room_script);
exit->SetNextRoomScript(next_room_script);
}
This is the code the reads the string from the text file and stores in into an instance of the Exit class by calling Exit:: SetNextRoomScript(), defined here:
void Exit::SetNextRoomScript(char* filename)
{
m_nextRoomScript = filename;
}
m_nextRoomScript is declared: char* m_nextRoomScript;
, as a private member of the Exit class.
It is retrived with the Exit::GetNextRoomScript() method, defined as:
char* Exit:: GetNextRoomScript()
{
return m_nextRoomScript;
}
Is there something wrong with the way I am letting the compiler convert a char array to a pointer to a char, or are they any other issues with scope I'm overlooking? thanks. :)