## Help needed - yet another newbie lost

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

diz
Posts: 41
Joined: Mon Jan 06, 2003 2:50 am
Location: Switzerland
Contact:

### Help needed - yet another newbie lost

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: Select all

`from Blender import *# a simple increment printed in the console for debug purposetry: test+=1except: test=0print test# if the variables are set output some debug info, else set themtry:   print bx   print ax   print link.loc.xexcept:   print "except"   bx=ax=link.loc.x   by=ay=link.loc.y   bz=az=link.loc.z# position=position+acceleration/16+speed*0.9link.loc.x+=(link.track.loc.x-link.loc.x)/16+(link.loc.x-bx)*0.9link.loc.y+=(link.track.loc.y-link.loc.y)/16+(link.loc.y-by)*0.9link.loc.z+=(link.track.loc.z-link.loc.z)/16+(link.loc.z-bz)*0.9# update variables for the next script callbx=axby=aybz=azax=link.loc.xay=link.loc.yaz=link.loc.z`

This works in Blender 2.23, and here's an output:

Code: Select all

`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: Select all

`0 # test never incrementsexcept # 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

Gabriel
Last edited by diz on Sun Jan 12, 2003 5:19 pm, edited 2 times in total.

theeth
Posts: 1184
Joined: Wed Oct 16, 2002 5:47 am
Location: Montreal
Contact:
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

diz
Posts: 41
Joined: Mon Jan 06, 2003 2:50 am
Location: Switzerland
Contact:
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

### Who is online

Users browsing this forum: No registered users and 1 guest