** pass global variable between bpy and bge !!! ***

Compiling, libraries, modules, coding guidelines and porting

Moderators: jesterKing, stiv

Post Reply
mchrgr2000
Posts: 0
Joined: Mon Aug 05, 2013 8:09 am
Location: Japan

** pass global variable between bpy and bge !!! ***

Post by mchrgr2000 »

Hi,

I use a bpy python script to create a system of objects and logic blocks.
This script does a sort of "initialization" setup things for a blender game.

The script create controllers, link them with sensors and assign controllers to python scripts.

To generate the objects and the logic blocks etcetera, I use the "ops" library, in this fashion:

bpy.ops.mesh.primitive_cube_add(location=pos[0])

A number of global variables are also defined during this initialization.
I save those variables to the scene using commands like:

sce=bpy.context.scene
sce["Stp"]=Stp

Once this is done the game is run using the key "p".

Once the game runs I would like to access some global variables that has been generated during the initialization process by bpy.

I do that, using again bpy, in this fashion:

import bpy
Stp=bpy.context.scene["Stp"]

My question is:

Is that ok to import bpy, even if I am running a blender game !??

Is this the only way to pass variable from bpy to a running game?
I heard about global dictionary. Can samebody indicate me the best way to generate a variable with a python script, and then read this variable during a game when bge is running?

I ask you this, because my software have several bugs, and I can't debug it properly. I have strange error messages, pointing to nonexistent script lines, or lines that correspond to older version of the script. Very weird stuff indeed.

I read in several forums "never not use bpy inside bge !" and I suspects my fancy bugs are due to the game importing bpy .... I may be wrong, but that's what I suspect.

Thank you very much if somebody can help !

Please add any information that you think it may be useful to me.

Greg Ruo

PS: by the way my "game" is not a game, is a sort-of experimental finite element method differential equation engine that I am trying, for fun, to put together.

Post Reply