I’ve got a working knowledge of python but I can’t identify the functions and how to use them to import Objects (a ship mesh) into my game from another blend file in another directory.
The basic idea is I’ll construct ships in separate files and then import them and their children into the game as necessary.
I’ve yet to run across a straightforward tutorial that works so I’m either searching with the wrong terms or the info I am finding is out of date.
If it is showing up after the game, then that means you are using the Blender Python API instead of the Blender Game Engine Python API. They are not the same. You cannot use the Blender Python API in games, because the standalone player does not support it.
Only use the functions in “Standalone” and “Game Engine” (the bge module). Do not use the bpy module (“Application Modules”), as that is the Blender Python API.
Dynamic loading is in bge.logic:
bge.logic.LibLoad() loads Meshes or Scenes from an external file.
bge.logic.LibNew() creates a library group from existing objects in memory.
bge.logic.LibFree() frees the specified library group from memory.
Thank you. Now I’ve got figure out how to use them properly.
I keep getting could not open blend file errors.
I’ve tried the following
bge.logic.LibLoad('TEST.blend', 'Mesh', 'H_Primary')
bge.logic.LibLoad('TEST.blend', 'Mesh')
bge.logic.LibLoad('''C:\\Documents and Settings\\dbramblett\\My Documents\\TEST.blend\\Object\\''', 'Mesh')
I assume that one must use LibLoad to get Meshes and or scenes into the game, then use LibNew to organize them into named groups, which you would then use LibFree to remove from the game. (Once I get LibLoad working anyway.)
…there must be some other problem. Just for fun I saved my target file in another location, C:\ and after updating the path it worked. The original file must have been flagged as read only somehow. I didn’t expect it to Load all objects in that file though. Experimentation continues.
How does the gamelogic variable suggestion work though?
Are we talking add a property to the game object, and somehow reference that?
Edit: Now its not working again and I’ve changed nothing. Quantum coding FTW!!! Grah.
Edit2: Now its working again. I think the real problem with my usage is that it does not like anything but the full file path and the rest was a PEBKAC.
Do not use the bpy module (“Application Modules”), as that is the Blender Python API
You know that explains a why lot of the things I have tried recently do not work, could my trying to use them also explain some crazy bugs that have crept into my blend in the last few days?
For example: I was trying to use the bpy module to delete overlays and now the dead player overlay only displays properly the second time it is called, though other overlays do not appear to be affected ???
If I’m reading the code right, the basic idea seems to be referencing Objects by a Property value rather than their object name. Which is somewhat ancillary to the task at hand, but none the less a useful thing to do. Rather than rely on a naming scheme you’d have a property listing scheme to index the object from code.
I can’t get the code to run though, partly because of the GameLogic depreciation, which I worked out for the most part on my own, but also because bge.types.KX_Scene.addObject() function won’t accept an argument.
If I use bge.types.KX_Scene.objects[2] it says it expects a KX_Scene object, rather than a KX_GameObject.
So if I try passing GameLogic.getCurrentScene() instead I get the opposite. It wants KX_GameObject rather than KX_Scene object.
GameLogic.objSpawn doesn’t seem to exist at all anywhere anymore. I’ve searched the API but can’t find a reference to the function.
I’m at a loss now. It only wants the opposite of what I pass into it.
Edit: Naturally it’s only on the verge of giving up and quitting after trying every combination and angle I could think of that something occurs to me an it works. For those of you who know what the hell you’re doing you probably know exactly what I was doing wrong.
So the next logical question is how does the ‘Mesh’ option work? It sounds like it allows you to pick and choose which objects you want to import.
Corollary to that, it seems that the ‘Scene’ option just dumps anything that was visible on the active layer into scene in the game and automatically adds those objects.
I want to avoid doing that so that objects don’t periodically flicker into view before being hidden on an inactive layer or moved elsewhere.