Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualBrentChua

Posted 23 June 2013 - 12:33 AM

Yes it includes the spaces unless you specify it in the delimiter. 

 

 

 


if(line[i + 1] == ',') tileNumX = (int)line[i];
if(line[i + 1] == ' ') tileNumY = (int)line[i];

 

You're directly casting a char value to int. I think that would not work. You're getting the ascii value of that char. Take a look at this ascii table here: http://www.asciitable.com/. For example if your current char is '0', its integer decimal value is 48. What you need is a function something like atoi(). This will properly convert a char number to its actual decimal value.

 

Also since you're getting huge amount of values, it may be possible that you're skipping those if statements completely without having the tileNumX and tileNumY assigned; just like what Servant of the Lord said. Try assigning a default value before you get your next x,y pair.

std::string line;
std::getline(m_MapFile, line);

tileNumX = 0;
tileNumY = 0;
for(int i = 0; i != line.size(); ++i){
...

Can we also see how you're arranging your map file?


#1BrentChua

Posted 23 June 2013 - 12:32 AM

Yes it includes the spaces unless you specify it in the delimiter. 

 


if(line[i + 1] == ',') tileNumX = (int)line[i];
if(line[i + 1] == ' ') tileNumY = (int)line[i];

 

You're directly casting a char value to int. I think that would not work. You're getting the ascii value of that char. Take a look at this ascii table. For example if your current char is '0', its integer decimal value is 48. What you need is a function something like atoi(). This will properly convert a char number to its actual decimal value.

 

Also since you're getting huge amount of values, it may be possible that you're skipping those if statements completely without having the tileNumX and tileNumY assigned; just like what Servant of the Lord said. Try assigning a default value before you get your next x,y pair.

std::string line;
std::getline(m_MapFile, line);

tileNumX = 0;
tileNumY = 0;
for(int i = 0; i != line.size(); ++i){
...

Can we also see how you're arranging your map file?


PARTNERS