I’ll do the basics first:
The simplest way to use Libload is to load a scene from a blend file. It will load the currently active scene, and any objects in the active layer will be added when it finishes loading.
path = bge.logic.expandpath('\\blend.blend')
bge.logic.LibLoad(path, 'Scene')
Voilla, your scene will load.
To get rid of it, you use LibFree:
bge.logic.LibFree(path)
And that’s pretty much all I ever do with LibLoad. These days I’ve been playing a bit with Async, but find that it can be a bit of a hassle. To use Async, you do something like this.
Initiate Load:
path = bge.logic.expandpath('\\blend.blend')
handle = bge.logic.LibLoad(path, 'Scene')
To find out how much it’s done (ie every frame to update a loading bar etc):
print(handle.progress)
You can also add a callback so that when it’s finished a function is run. This is probably meant for removing the loading bar:
def end_loading(status):
print('I am finished loading the file')
handle.onFinish = end_loading
I’m not quite sure what status is, but I’ve never had to use it. Probably a simple True False thing?
So, about your specific questions:
1)How load directly a object from another file?
Have it in an active layer and use libload with type ‘Scene’ is one way. Otherwise you can use type ‘Mesh.’ I have not tried this method so I can’t tell you exactly how to use it. Perhaps someone who knows could tell me? I’m keen to learn.
2)How load a scene, and in other moment load a specific file of this scene.
See the stuff above for how to load it. But I think what you are asking here is how to load a scene, but not show anything and then later add objects from it?
In this case, yeah, go ahead and load it using type ‘Scene’ but make sure you saved it with all objects on inactive layers. Then from in the game, you can simply search the inactive objects, and add it from there.
(It’s bge.logic.getCurrentScene().objects_inactive I think)
3)How delete later the objects added.
The same way you remove other objects: grab them from your script and use end_object (or logic brick equivalent), or libFree the library, the game engine will remove them for you, but they will no longer be able to be added. (and anything else from the blend will vanish)