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

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
kennypu666
Posts: 26
Joined: Thu Apr 26, 2007 6:57 am

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

Post 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
mqrk
Posts: 16
Joined: Mon Dec 10, 2007 5:55 am

Post 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.
Post Reply