Previous Thread  Next Thread

chat icon Variables don't stay in 2.25

m.hertel

Posted: Tue Nov 05, 2002 4:02 pm
Joined: 05 Nov 2002
Posts: 3
Hello,

after upgrading from 2.23 to 2.25 scripts like
the following (linked to FrameChange) stop working:

try:
print conn
execpt:
conn = "something"

In 2.25 continuesly a exception is thrown. In 2.23
only the first time, when conn is undefined.

Any ideas?
Reply with quote


markluffel

Posted: Wed Nov 06, 2002 8:07 am
Joined: 19 Oct 2002
Posts: 13
The way I understand it, older blender keep a single python interpreter active and in the same namespace. It seems 2.25 doesn't do this. Therefore your variables are destroyed at the end of each script run.
This state will not continue for long.
Reply with quote


m.hertel

Posted: Wed Nov 06, 2002 9:51 am
Joined: 05 Nov 2002
Posts: 3
Yesterday, I tried writing a python C API Module.

For testing I've placed some printfs() in it. The Module init-Function
is only called once during Alt+A.

Maybe the variable thing is a bug?
Reply with quote


eeshlo

Posted: Wed Nov 06, 2002 10:14 pm
Joined: 06 Nov 2002
Posts: 130
m.hertel wrote:
Yesterday, I tried writing a python C API Module.

For testing I've placed some printfs() in it. The Module init-Function
is only called once during Alt+A.

Maybe the variable thing is a bug?


This is not a bug. There are reasons for it, it keeps thing a lot cleaner for one. When you run a script, everything that it imports and creates doesn't go away even when starting with a new scene unless you restart Blender (Blender <= 2.23). C/C++ Extension modules are only initialized when first loaded.
If you really want to do this in Publisher you can use the same trick as the blenders gamers might use in their python scripts: make your variables attributes of the Blender module itself:

Code:

import Blender

Blender.myVariable = myVariable_value


And of course myVariable can be anything, any python object. This will 'stick' untill you quit Blender, you can start with a new scene (ctrl-x) and the variable will still be available.
Reply with quote


m.hertel

Posted: Thu Nov 07, 2002 8:08 am
Joined: 05 Nov 2002
Posts: 3
That is what I want. Now my script is running with 2.25, from which I need some features.

I always was a bit apportioned about the variable stay thing.
On one side it helps keep variables through the time. On the
other side, during development there are some problemes, scripts
stop working after next start of Blender...

Making it a attribute of Blender is the much better way. I just didn't know that this is posseble (I'am quite new with python).

Thanks for help!
Reply with quote


 
Jump to:  
Powered by phpBB © 2001, 2005 phpBB Group