There are many ways to do this. You can also create a function to return a 'free' object ID. With this function for example:
int FreeObject()
{
for (int i=1;i<99999;i++)
{
if( dbObjectExist(i) ==0)
{
return i;
}
}
return 0;
}
You could use that then with your existing code like this:
if(dbMouseClick() == 1 && lastMouseState != 1)
{
int TempID;
TempID = FreeObject();
dbMakeObjectCube (TempID, 10);
dbPositionObject (TempID, 50, 0, 50);
}
Works very nice if you just want to create some objects. But it also has its downsides. Its not super-uber fast, you have to do a linear search through all ID's which are not available. And when you want to know how many objects you have you should do another kind of linear search, instead of knowing directly what the object count is in your scene.
I use it mostly with a linked-list system. In a way I never have to worry about my object ID's. Small example of what I mean:
c_3dObject JustAnObject;
JustAnObject.Create("modelfile.x");
JustAnObject.position.x=234;
JustAnObject.Update();
Posibilities are endless!