Thread: small reference problem

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Location
    Plano, Texas, United States
    Posts
    2,743

    small reference problem

    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:
    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;
    }
    Anyone see anything I am doing wrong?
    Last edited by DavidP; 06-21-2004 at 12:50 PM.
    My Website

    "Circular logic is good because it is."

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 05-13-2011, 08:28 AM
  2. Using Vectors. MinGW warning
    By Viewer in forum C++ Programming
    Replies: 9
    Last Post: 03-26-2009, 03:15 PM
  3. Problem with Makefile
    By pinkprincess in forum C Programming
    Replies: 3
    Last Post: 06-24-2007, 09:02 AM
  4. Small Problem in C, Please Help.
    By DoctorFu in forum C Programming
    Replies: 6
    Last Post: 10-31-2005, 03:06 PM
  5. compiler problem
    By sofarsoclose in forum C Programming
    Replies: 3
    Last Post: 07-10-2003, 11:39 AM