Load new scene / .blend with Python?

Hi,

I’ve been checking the Yo Frankie files and found that it makes a use of 2 actuators to load scenes/blends :

  1. Scene-> Set scene (called “portal_scene” in frankie.blend)
  2. Game-> File (called “portal_blend” in frankie.blend)

I have tried to find in the documentation on how to do it with Python.
But I thought that, if it’s not used in the updated version of Yo Frankie, maybe that means that this method is not available?

Questions

  1. So, can I load new scenes / .blends with Python, without actuators?

  2. Is that possible to add a group of objects (same group, or all parented to the same object) in a .blend where it is not linked yet? I mean, without using a loop (add every obj in obj.parent list).

  3. Do I need an empty in the next scene to add my main object after it’s teleported, or can I do it directly from the script?
    The problem is that the actuator “Game->File” is activated (cont.activate) at the end of my script.

And once the new blend is loaded, my script is not active anymore because the object is not in the scene.
Is there any other solution than having an empty in the next scene adding the main object if it doesn’t exist?
I’d like to centralize that operation.

Thank you.

I bump this thread because it didn’t get much attention and will disappear soon.
I think that it could benefit a lot of people to know the answers.

I know that people here don’t like bumps so… here is a picture (for fun).
http://www.aandria.com/wp-content/gallery/illustrations-jeunesse/bears.jpg

  1. I don’t think so.

  2. You can add a dupli-grouped object and that will add all objects of that group automatically. Say you linked your character from another .blend who is in the group “Char”. You can add that to the scene by doing Add->groups->Char. That will add an empty dupli-grouped to your Char group. That empty name defaults to “Char”. So if you call GameLogic.addObject(“Char”, center) that will add another instance of that empty which automatically adds the whole “Char” group to your scene.

  3. I’m not sure what you’re saying here. Do you want to control the creation of an object on Scene 2, after Scene 1 doesn’t exist anymore from a script that was running on Scene 1? If so, I don’t know any clean way to do that. But I don’t know why you’d want to do that either. To run any logic on a scene, you need an object there. I would just move to Scene 2 and program that empty on Scene 2 to deal with creating the main object again. Not sure why you’re trying to avoid this. Unless I’m understanding you wrong?

Hi vibrunazo,

  1. that would be great if we could
    => LoadScene(“Scene2”)
    => LoadBlend("//level2.blend")

  2. I’ll take a look at dupligroups (never used that).
    What I want to do is add a character (collision box + mesh + camera etc) in a .blend that I don’t have access. (see explanations in 3).

  3. Yes, I know that it would be easier to do it with an empty that would already be in the scene.
    What I want to do is : different users upload their levels on a shared folder.
    I would like to use a single .blend to launch another blend/scene and add a list of objects automatically. I don’t want the levels to be modified : I just want to load a list of objects at startup.
    I want to be able to change the list of objects to be added in a centralized way.
    I don’t want to open all the levels to add it, and don’t want the users to add an empty/copy scripts.

Let’s say that a level designer is working on a new level. I can test it and play a bit (add LOD, dialogs scripts, etc etc) by launching my single .blend.
The level is not modified at all.
I hope my explanations are better :slight_smile:

Thanks for your answers.

Oh you can just do it like I’m doing it then. Instead of having the level as the central .blend where everything loads on. You can just have this centralized .blend for the engine, and that blend will load characters and also the levels. Just like you load characters, with linked groups.

All the level designers need to do is make sure all objects that are part of the level are grouped in a group called “level”. Then you just link to the level .blend and add a new object for the “level” group. Just as you would for a character.

Then you could have all functionality centered on that one “engine” .blend which loads all characters and levels into it.

Another way that could proly work as well. Would be having a BackgroundScene with your level/chars and edit that scene externally from your main scene. Then you could remove that scene and add another one, to change levels.

But I need to link/append manually to my .blend, right?
So if users upload xxx files, I would need :

  1. to link all of them to my .blend and always be sure to keep the list updated if users remove/add/rename their levels
  2. to be sure that each one uses a unique name

I would like to avoid that and with Python, do something like : loadBlend("//test.blend"), load_Dict(“player_Dict”), addObj(Obj_List).
So I can change from one level to another within a few seconds, not “delete group level_”, “add group level_2”.

But I know that I’m a bit dreaming :slight_smile:

Well dynamic linking is coming an from what I understand (not 100% sure) you can load a whole scene from an external .blend. So you could just keep swapping BackgroundScenes from level to level. Would have to double check Ideasman42’s old video examples and see how it was done. That surely is gonna make everything easier.

If you don’t wanna wait, you could just do it like yoFrakie does it. And have a “level template” that users start building their level from. So they don’t need o worry about copy/pasting code or linking libraries. Then you just change levels by changing .blends. It’s not ideal, but I think that’s the easiest solution for what we have today.

But note that this is only a problem if you want levels to be fully customizable .blend files. On most games this is not the case. You usually don’t give the level designer to go as low level as he wants and to whatever. He usually have this limited yet flexible set of tools made by your company’s software engineers that let him build level using the existing models and meshes.

You could use the BGE to do something similar. You make a map editor that lets the user place/remove objects from a database. And raise/lower terrain. Then you save that data as a “level” file that you’ll load on your central engine. You’ll be giving up a lot of low level flexibility by going this route. But you make everything more standardized and reliable.

Hi Vibrunazo,
I am well aware of the setup in YoFrankie (level template => library.blend) because I’ve been using this for months (even for the template that I released).
This is a very good one.
In fact using level designers was a bad example : “simple users” upload a .blend (whatever they want, a cube, a complete map, an abstract visual effect, whatever) and I add my group of objects in the first scene available, at a default position.
Those users should not have any knowledge about level designing.
That’s why I wanted to find another setup.

If not talking about a game, I can imagine people uploading a .blend with photos mapped on planes.
If I can add my object dynamically, I can put the object in front of the mapped planes and create a diaporama. Just an example of what is possible.

I will check the videos from ideasman42 twice, and be patient until 2.5 is available.
Thank you for your answers.