moving a group of one node.

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
roelor
Posts: 240
Joined: Wed Aug 13, 2008 8:06 am

moving a group of one node.

Post by roelor »

Hello,

I want to move my ground with the player on a grid, but when I call node->setPosition(); it tells me that the node wasn't declared in this scope.

This is my ground code:

Code: Select all

int i=0,I=0;
            while (I!=4||i!=4){
		    if (i==4){I+=1; i=0;}
    IMeshSceneNode* ground = smgr->addMeshSceneNode( grmesh );

    if (ground)
    {
        ground->setPosition(core::vector3df(256-i*128,0,256-I*128));
        ground->setMaterialFlag(EMF_LIGHTING, true);
        ground->setMaterialTexture( 0, driver->getTexture("../../media/detailmap3.jpg") );

    }
    i+=1;
		}
And this is the code in the running/drawing loop:

Code: Select all

    ground->setPosition(core::vector3df(
    ground->getPosition().X+round(nodePosition.X/128)*128, 0,
    ground->getPosition().Z+round(nodePosition.Z/128)*128));
I (think I) know what I am letting the program trying to do (calling a script to move one node whilst it are multiple nodes), But I want to move all the ground nodes.
yamashi
Posts: 82
Joined: Sat Jan 03, 2009 4:53 am

Post by yamashi »

You never declared node...
use groud->setPosition() instead ...
CuteAlien
Admin
Posts: 9716
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Variables have to be declared inside the scope (usually between the {} braces) to be used.

Also another hint about that line: if (i==4){I+=1; i=0;}

Look up the % operator (called modulo). There's a good chance that it does what you are trying to do there.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
roelor
Posts: 240
Joined: Wed Aug 13, 2008 8:06 am

Post by roelor »

CuteAlien wrote:Variables have to be declared inside the scope (usually between the {} braces) to be used.
What variables?
When I comment out the second code everything works, I created a bunch of nodes with the same name, Are you sure its not a mishap there?
CuteAlien
Admin
Posts: 9716
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

roelor wrote:
CuteAlien wrote:Variables have to be declared inside the scope (usually between the {} braces) to be used.
What variables?
All variables. You can't use one that isn't declared in the scope in which you try to use it. You can use everything from everywhere when it is in the global scope (declared outside your classes functions) - which is not recommended! All local variables are only valid within their local scope. Which is usually defined by the {} braces. Membervariables can be accessed by their class-object (if that is declared in a local scope).

I give you an example:

Code: Select all


// declared outside functions. Will be global.
int global = 1;

// some function, param is valid only within Foo
void Foo(int param)
{
  int local=2;  // valid within the function (same as param)
  {
     int small_scope =3;  // only valid until next }
  }
//   int y = small_scope; // this would get you an error because small_scope no longer valid here
}
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
roelor
Posts: 240
Joined: Wed Aug 13, 2008 8:06 am

Post by roelor »

Ah, I get it. since I declared ground in a while loop ground isn't defined outside it. but how would I move it. Or is it just impossible this way?
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

You just have to split definition and assignment.
Post Reply