bah...been programming in C++ for over 6 years now and i still have the occasional problem with a reference or two
Anyways...im probably just too frustrated to see the problem right now. Let's see if any of you guys can spot it.
This is simple snippet of code that spawns the a barracks building on the map at coordinate (x,y) in my RTS game. For some reason the code that flags the terrain as impassable is not working. (The code in the nested for loop at the bottom of the code snippet).
It was working before I put it in the function (I had it sitting in the main function for testing, then I encapsulated it in this function), and now it doesnt seem to work. Therefore I presume it is a problem with the reference, however, I don't know why there would be a problem, because reference variables are supposed to hold their changes. They are not copies made just for use inside that function. Reference variables are originals and therefore the map should hold any changed made to it, yet for some reason it is not holding these changes that I am making to tile passability.
Here is the code snippet:
Anyone see anything I am doing wrong?Code:bool Spawn ( int x, int y, MAP_DTP &map ) { LoadAnimation ( "animation\\barracks.anim" ); SetEntityName("Barracks"); int TwX = ConvertGridToWorldX ( x ); int TwY = ConvertGridToWorldY ( y ); SetWorldCoordinates ( TwX, TwY, 0 ); ConvertWorldToScreenCoord(map); int gXf = ConvertWorldToGridX ( WorldX + widthPerFrame ); int gYf = ConvertWorldToGridY ( WorldY + heightPerFrame ); //This nested for loop is the problem. //I set the passable variable to false in each specified spot on the map. //The map should hold the changes because it was passed by reference. //However the changes do not have any effect after the function exits. for ( ; x < gXf; x++ ) { for ( ; y < gYf; y++ ) { map.terrainMatrix[y][x].passable = false; } } return true; }