Hy all! I'm really needing some help, I spent really a lot of time with some trivial-looking problems. So if you could please take some time to have a look at my problem, this would be very appreciated!

I'm a complete python beginner, and in order to learn the basics of the blender scripting, I intended to make a simple two-particle system with the particle number 2 being attracted by number 1 (particle 2 tracks particle 1). So here's my code:
| Code: |
from Blender import *
# a simple increment printed in the console for debug purpose
try: test+=1
except: test=0
print test
# if the variables are set output some debug info, else set them
try:
print bx
print ax
print link.loc.x
except:
print "except"
bx=ax=link.loc.x
by=ay=link.loc.y
bz=az=link.loc.z
# position=position+acceleration/16+speed*0.9
link.loc.x+=(link.track.loc.x-link.loc.x)/16+(link.loc.x-bx)*0.9
link.loc.y+=(link.track.loc.y-link.loc.y)/16+(link.loc.y-by)*0.9
link.loc.z+=(link.track.loc.z-link.loc.z)/16+(link.loc.z-bz)*0.9
# update variables for the next script call
bx=ax
by=ay
bz=az
ax=link.loc.x
ay=link.loc.y
az=link.loc.z
|
This works in Blender 2.23, and here's an output:
| Code: |
64 # test
-5.84074544907 # bx
-5.66258335114 # ax
-5.66258335114 # link.loc.x |
The first very strange thing is that I have to create two variable triplets (a* and b*), because a* is always the same as link.loc.*. Do you have any explaination for this behavior
Second problem, in Blender 2.25 this doesn't work, here's an output again:
| Code: |
0 # test never increments
except # never entering the "try:" code |
So my try-except stuff doesn't work, because the global variables don't seem to be preseved from one script call to another... But why
Thank you for having read my problem, and if any of you has any idea or suggestion, please help me.
Gabriel
Last edited by diz on Sun Jan 12, 2003 5:19 pm; edited 2 times in total
Ok, but that there *must* be a way to preseve a variable between two script calls. Otherwise this would be a *huge* restriction, because it wouldn't even be possible to transfer a variable between two scripts, two frames, ... Well in fact I hope there is a way of doing it...
Anyway thanks for the tip, actually the only solution I found was to go on working in Blender 2.23.
Gabriel