A few questions about BGE + Python

Hello, I’m a complete newbie to pythoning in in the BGE. I’ve read the manual and tutorial on blender.org and I’ve read the python in BGE starter guide. And that’s all that I know about Python on the BGE. I’ve tried to look through the YoFrankie files to understand it better but that was too overwhelming for me. I’m stuck trying to figure out these:

1- On many examples that I’ve read, there is a keyboard sensor linked to a python controller and a motion actuator. But the script will often contain code that seems unnecessary to be repeated everytime I press a button. Such as importing modules, setting variables to each sensor etc. That is repeated every game tick. Which seems like a waste. Is that the only way to do it? Or can I just set all these variables on one big initialization script and then just use the controller script to calculate the logic and activate/deactivate the actuators?

2- Can I make one initialization script that will create logic bricks for all objects and connect them, using Python only, without having to deal with the F4 interface (maybe only use the interface for the init script)? How?

3- One thing I want to do is to have procedurally generated meshes and objects. I know how to create Add->Mesh scripts. But I have no idea how to make those work in the GE in real time, is it possible?

4- On most Yo Frankie scripts. It simply defines a couple of functions then defines a main() function. But I cannot find it anywhere how the main() function is called, I just find the definition. Shouldn’t it call it somewhere is that some native aspect of Python or the BGE that I were not aware of?

5- I read that I can only use the action actuator for bones. But what if I wanna change the action of an object with no armature? I thought of changing the current IPO curve for the IPO actuator but I didn’t find anything about this on the GE API. Maybe I can use something from the non-GE Blender API to edit the object IPO curve in real time?

6- How often is a game tick? I read about it a lot on the docs, but I couldn’t find how many game ticks are there in 1 second. Could I possibly adjust this value?

7- The “Show Framerate and profile” option doesn’t seem to work on a standalone runtime. Is there a quick native way to display the FPS in runtime so others can help me benchmark it?

Thanks in advance ^^

  1. python controllers that execute as a module can work around this to some extent. since only the function runs every logic tick (called main() with my own scripts), anything defined above the function definition only runs once. This can speed up scripts.

  2. you cant create and connect logic bricks with python currently. but you can make init scripts, I find states good for this.

  3. no, offering to write this :slight_smile: - http://blenderartists.org/forum/showthread.php?t=160736
    however you CAN move verts about with python this doesn’t really count.

  4. the controllers call the function.
    you can see the controllers can something like
    “frankie_scripts.init.main”
    This is new in 2.49, I used the function name “main” to avoid confusion however there is nothing special about that name, it could be anything else.

  5. actions currently only work with armatures and mesh shape keys, not objects.

  6. 60 a second by default. I think you can change in the world settings. you can change in python too.

  7. the python rasterizer module can get the average framerate, see BGE docs.

Oh so that was more useful than I thought ^^
But can I use edit mode mesh tools to create a mesh, such as these. To edit and create objects?

Similarly, I did some testing and tried to move an object during game by editing it’s LocX parameter instead of using actuators but couldn’t get it to work. Is it possible? Or is there some disconnect them normal Blender API and the GE API?

That is great news. I just found the video you made about it. I’ll add it to the blender wiki once I get a better hang of it ^^

But is it possible to simulate that using the IPO actuator? The only limit in the IPO actuator is that it cannot change the IPO curve the object is using. Can I change it via python?

Thanks a lot for your time. It helped me a lot :slight_smile:

Generally the Blender module should not be used in the BGE. Considered removing it while running the BGE, maybe I should have though it is useful to read data still (but changing the data mostly wont do what you expect). the Blender module is not available in the player either.

Re 5) Im not sure what you mean, an object can only have 1 ipo. afaik there is no way to select different ipos once the game starts.