Page 1 of 1

help please, saying pointer is undeclared when it was!!??

Posted: Fri Dec 21, 2007 6:54 am
by kennypu666
Hi again, sorry but I need help again. For somereason, the compiler is saying that a pointer/variable (not sure), is undeclared, but was obviously declared before it. Are there any reasons why it would do that?(other than misspelling ;) ).Sorry, its in middle of a if statement, but heres the code:

Code: Select all

            
             //get a mesh from name
             IMesh* roommesh = smgr->getMesh(roommesh_name.c_str())->getMesh(0);
            ITriangleSelector* selector = smgr->createOctTreeTriangleSelector( roommesh,roommesh_node,128);
             roommesh_node->setTriangleSelector(selector);
             selector->drop();
        }
    }

    //camera( in the scene)
    ICameraSceneNode* cam =  (ICameraSceneNode*)smgr->getSceneNodeFromName("cam_player");
    

    
    //camera
    ICameraSceneNode* cam1 = smgr->addCameraSceneNodeFPS();
    cam1->setPosition(vector3df(0.0f,0.0f,100.0f));
    
        ISceneNodeAnimator* anim = smgr->createCollisionResponseAnimator(selector,cam1,vector3df(30,50,30), 
		                     vector3df(0,-3,0),//(o,-3,0) 
                       vector3df(0,50,0));
	cam1->addAnimator(anim);
	anim->drop();
 
the compiler gives an error at the decaration of anim saying that 'selector' is undeclared. Please help, any suggestions, help is appreciated. thanks in advance,
Ken

Posted: Fri Dec 21, 2007 7:16 am
by mqrk
You can't declare a variable inside a code block and then use it outside of the block (it's out of scope). Think about it this way: What if the condition of the if statement is false? Declare the variable before you enter the if block.