glLoadName() - Help

Hi,
I am making a game where I create objects pressing a button. And each object is pickable. But my problem is when I pick a single object, all other objects get selected. I just want to select one object at a time.
Here is the code:
// draw an object
for(GLint i=0; i < CubeMesh; i++){
for(GLint j=0; j < CubeName; j++){
glPushMatrix();
glTranslatef(0,0,0);
glLoadName(j);
Cube[i].Draw();
glPopMatrix();
}
}

And the selection is:
for(GLint i=0; i < CubeMesh; i++) {
if(hits) {
int n=0;double minz=buff[1];
for(int j=1;j<hits;j++) {
{
if (buff[1+j4]<minz) {n=i;minz=buff[1+j4];}
}
}
Cube[i].selected = true;
}else{
Cube[i].selected = false;
}
}

Thanks in advance.

Never mind. got it :slight_smile: