Making a multiple versions of a Object

122 Views Asked by At

I'm a student instructed to make a doodle jump replica with ogre3d. I have a function which should make a panel on screen with a designated shape and location so now I wish to make a for loop that will make multiple (up to 10) and a random value that'll set each of them somewhere different on x,y,z.

void PlatformManager::CreatePanelDoodle( float x, float y, float z){

    
    Plane plane3(Vector3::UNIT_Y, 0);
    MeshManager::getSingleton().createPlane(
        "Paddle2", RGN_DEFAULT,
        plane3,
        20, 5, 20, 20,
        true,
        1, 5, 5,
        Vector3::UNIT_Z);
    Entity* groundEntity3 = scnMgr->createEntity("Paddle2");
    SceneNode* Paddlenode2 = scnMgr->getRootSceneNode()->createChildSceneNode();
    Paddlenode2->setPosition(Ogre::Vector3( x, y, z));
    Paddlenode2->attachObject(groundEntity3);
    groundEntity3->setCastShadows(false);
    
}

and this is for attempting to make multiple objects in random space

point plat[20];
    float pX;
    float pY;
    for (int i = 0; i < 10; i++)
    {
        plat[i].x = rand() % 50;
        plat[i].y = rand() % 30;
        float pX = plat[i].x;
        float pY = plat[i].y;
    }
    

    for (int i = 0; i < 10; i++)
    {
        PlatformManager Panels = new PlatformManager->CreatePanelDoodle(pX, 0, pY);
    }
    

The problem is with the error in the for loop creation "No suitable constructor exists to convert void to "platform manager"

I've tried simply adding the constructor into the for loop, and not using the loop at all. Whats going wrong?

1

There are 1 best solutions below

0
Thomas Sablik On

There are some problems in your second code snippet:

  • You are using uninitialized variables float pX; and float pY;
  • You are shadowing variables with float pX = plat[i].x; and float pY = plat[i].y;
  • You are creating multiple random values but you are not using them
  • You are trying to apply the new operator on a void function
  • You are trying to store that result in a variable

You can solve the problems with

// Remove this block, you don't use the variables
/*
point plat[20]; // You don't use this array
float pX; // You use it uninitialized
float pY; // You use it uninitialized
for (int i = 0; i < 10; i++) {
    plat[i].x = rand() % 50;
    plat[i].y = rand() % 30;
    float pX = plat[i].x; // You don't use this variable
    float pY = plat[i].y; // You don't use this variable
}
*/

for (int i = 0; i < 10; ++i) {
    PlatformManager->CreatePanelDoodle(static_cast<float>(rand() % 50), 0, static_cast<float>(rand() % 30));
}