Project works in 2.40 - not in 2.41 - Python problem?

Hi there

I have a game with lots of Python scripts that works with 2.40 and not 2.41 (Windows 2000 or Suse 10)

I get loads of errors (which prevent the game running) from the console mainly along the lines of

NameError: name 'player_sensor' is not defined

Any ideas? I really want to use Bullet Physics in 2.41 which has less bugs.

thanks in advance

Whats the full code you are using? It would be easier to identify where the error is coming from if you provided the code that causes it.

It seems that the 2.41 Blender is more strikt on the variables live time. If you have local variables in a script it will only live as long the script runs. The next run of the script will not have this variable anymore.

You should use the properties of your objects to store variables (e.g. own.variable). It is also possible to define properties only visible in python. Alternatively you can define variables to the GameLogic accessable from all objects.

Make sure that they exist by using hasattr() before you read them.

if hasattr( GameLogic, "variable"):
    GameLogic.variable = GameLogic.variable + 1
else:
    GameLogic.variable = "new"

print variable

Check https://blenderartists.org/forum/viewtopic.php?t=62533&highlight=

you cannot add int to string.
you should have GameLogic.variable = 0 (or anny other number)
not that this was what you was trying to show, but… :wink:

You are right. Maybe add str(1) or initialize with 0. (This demonstration was to quick and to dirty :expressionless: ) Thanks NOR.J

My code is horiffic and it would take ages for other people to decipher it. There are about 10 scripts running concurently in the scene. I can’t imagine anyone having the patience to go through the scripts :smiley:

Monster - I’ve already got loads of properties on objects but I guess I’ll have to transfer them from the python script. If thats what it takes. Ps don’t tell Erwin your using Global Variables!

thank you everyone

Btw is this new behaviour intended or is it a bug?

Shall we pester Erwin about it?