Realtime python in game engine for 2.5?

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

Post Reply
Posts: 110
Joined: Wed Oct 16, 2002 6:52 am

Realtime python in game engine for 2.5?

Post by Saluk »

This is a proposition, somewhat of a pie-in-the-sky one; but it would be extremely useful for the python interpreter in the game engine to be converted to a realtime one. Currently, when it needs to run a script, it halts game execution, runs the interpreter, exits, then updates the changes. I read over the architecture Erwin posted, and while I didn't understand all of it, it seems to back up my theory. This is why you can't have global variables, because the interpreter quits when the script does.

There are some things with python in the game engine that don't work quite right because of the way it executes. If you want to add an object, and then set the object's properties, you have to do it in two steps. Add the object on one run, let the script end so that the engine is updated and the object is ACTUALLY added; then run the script again and try to access the object we just created to set it's properties. Not the simplest or most elegant thing in the world. It also creates a lag between script execution and results that makes certain things impossible (controlling a skybox on a seperate scene through python looks really bad, even though the lag is only one or two frames). If there was one interpreter, that worked something like IDLE (where you can execute scripts in it, and it's state remains persistant) then I think the flow would be much easier to deal with.

I don't know how much work this would require, or if it would even really benefit in the long run, but it would make more sense to me.

Another much simpler change would be to have every script not only automatically import GameLogic, but come with the object and all sensors, controllers, and actuators set up. A small thing, but it can get annoying when writing a lot of scripts to have to put the same stuff at the top every time.

Posts: 6
Joined: Mon Oct 14, 2002 2:22 pm

Post by jasper »

Hi Saluk

Maybe I can answer some questions for you,
I was at the Blender Conference, heard some things there.

I'm not sure if your right, but I'm no 'real' programmer :roll: so.

About the add Object. It is actually possible to retrieve the Owner from an added object, so you can add an object and set it's properties in one go, from one script.

Globals don't work as a result of the security issues from the game engine plugin. (I guess it's to risky) ?

However it's possible to use globals by just attaching a variable to the gamelogic object, although this is far from perfect because it does weird scope things when you attach a python class, and it's just plain ugly. Their must be a better solution then this?

Just like the owner object, you can add a string,int,float to it, but you can't add a list or dict, or other objects.

I guess this is because i heard Erwin say that the python code contains direct pointers to c++ classes, eg owner

All my objects in blender have the following script:


Then there's one object with this code:

GameLogic.Objects = {} #a python dictionary

This way you can reach all objects (with the script attached) in all scripts.And you can trigger actuators, etc .

It would be nice if this could be done automaticly

(Actually I do not use a dictionary anymore, but a class with some methods for rotating and uv 'scrolling', I posted it ones on Elisisyum (u:blendedHKU, gameEngine forum))

Ok, hope this souds a bit coherent.

Took me a loooong time to find some of these things out,
and I really think a new Gamelogic module would be nice.

It could just use the current features, but make it more like the 'normal' Blender module (GameLogic.Object.get())

What I would find really cool is if you could create sensors and actuators dynamicly at runtime:
act = GameLogic.newMotionACtuator(owner)
something like that?

Man, then I'ld never have to draw those black lines again :)

I talked to Erwin about this, and he said that it shouldn't be to hard.

I also have the following idea, what if someone hacked the python controller object, and make it not only check if the text object is in blender, but also in the current working directory. If it finds a txt file there, it will use that.

This way you could edit a blender python script in your favourite editor, save, goto blender and press p ,when it automaticly loads the txt file.

That would be a feature I would appreciate much more, then improving the builtin script window. (which is nice to, but a project at itself)

In the end I agree with Saluk that the python interpretor is hard because it runs all scripts every frame, which is not a normal convention in python programming ;)

However, it it possible -thrue a very bizar way- to script your game in one textfile so it becomes a bit more manageable.

But i guess a lot of stuff will change when we have a new working gameEngine again. Maybe better to wait till then.


Posts: 110
Joined: Wed Oct 16, 2002 6:52 am

Post by Saluk »

Yeah, I know all those little tricks and stuff. You CAN get an added object with one script, but you still have to do it in TWO passes. I just think that besides all the fun stuff it would allow, an actual running python interpreter would make more sense then the way it does things, of course I don't really know how it works exactly:)

You can import an external script fairly easily and execute it with the exec command if you want to write everything outside of blender, but sometimes the path is not correct. On some computers it doesn't know the path right, which is why I still haven't released my multiplayer demo, I have a ton of dependancies on python classes, and when I include the dependancies with the blend some computers wont import them right. I think this is more to do with python than blender though.

And being able to create your own logic bricks from python would be a nice feature, although being able to truly create your own OBJECTS and MESHES would be the best feature of ALL. I'd DIE if we could make our own objects and meshes such as is possible in non-interactive python!

Maybe we should start a new thread on that feature?

Post Reply