Previous Thread  Next Thread

chat icon Help needed - yet another newbie lost

diz

Posted: Tue Jan 07, 2003 2:02 am
Joined: 06 Jan 2003
Posts: 41
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!

Arrow 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 Question

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 Question

Thank you for having read my problem, and if any of you has any idea or suggestion, please help me. Wink

Gabriel

Last edited by diz on Sun Jan 12, 2003 5:19 pm; edited 2 times in total
Reply with quote


theeth

Posted: Tue Jan 07, 2003 5:10 am
Joined: 16 Oct 2002
Posts: 1177
diz wrote:
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

As far as I understood, In 2.25, the Python interpreter is restarted everytime you run a script, so variables are not preserved.


Martin
_________________
Life is what happens to you when you're busy making other plans.
- John Lennon
Reply with quote


diz

Posted: Tue Jan 07, 2003 11:26 am
Joined: 06 Jan 2003
Posts: 41
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... Sad

Anyway thanks for the tip, actually the only solution I found was to go on working in Blender 2.23.

Gabriel
Reply with quote


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