Page 1 of 1
Scripting: Error at line nr XX...but no error???
Posted: Sun Oct 31, 2010 12:39 am
by DragonsSpirit
Hi
I just loaded an old script I made for RF4 into RF5. In RF4, it works fine, but when I setup the exact same scene in RF5 and then load the script, RF will tell me "Error at line nr 27" everytime I start simulating. Line 27 is entirely empty by the way. It is just to separate a one block of code from another. I tried to make that line a comment or also delete it...does not help. When I offset the entire code +1 or -1 or whatever, the error is still there (but maybe line number changes). I dont understand...I checked other scripts, and some of them work perfectly. but others show the same behavior, they will not work because an error may come up in any line which is, without doubts, empty or correct.
The error message is always related to "None type object has no .... getParameter". Dont understand what is wrong

Again, RealFlow 4 takes the script and it works fine (though it sometimes says "error at line -1", with other scripts).
thanks for reading and have a nice day.
Re: Scripting: Error at line nr XX...but no error???
Posted: Mon Nov 01, 2010 10:39 am
by Alex
Hi,
sorry, we really need to improve the information provided by the scripting error messages.
Meanwhile, can you post the fragment of code where you are initializing variables that call the "getParameter" function?
It seems like if some functionality had changed since RF4 in some of the functions used before that sentence.
Re: Scripting: Error at line nr XX...but no error???
Posted: Tue Nov 02, 2010 7:35 pm
by DragonsSpirit
sure....here it is:
#--------------------------------------------------
# Function: onSimulationBegin
#--------------------------------------------------
def onSimulationBegin():
pass
#--------------------------------------------------
# Function: onSimulationStep
#--------------------------------------------------
def onSimulationStep():
import random
cp = scene.getObject("Control_Pressure")
ca = scene.getObject("Control_Age")
ch = scene.getObject("Control_Height")
cv = scene.getObject("Control_Velocity")
pos_y_cp = cp.getParameter("Position").getY()
pos_y_ca = ca.getParameter("Position").getY()
pos_y_ch = ch.getParameter("Position").getY()
pos_y_cv = cv.getParameter("Position").getY()
#THATS IT.....after that, the code is separated by a comment line and then goes on.
Re: Scripting: Error at line nr XX...but no error???
Posted: Wed Nov 03, 2010 5:32 pm
by FlorianK
post the same script into a common text editor (e.g. windows notepad). Sometimes, there are some poltergeist format signs/ escape sequences added in the text buffer, messing up your Python- indents. In most cases you can find those poltergeists when pasting your code/ opening your code with notepad. At least, that worked for me several times. Good Luck.
Re: Scripting: Error at line nr XX...but no error???
Posted: Thu Nov 04, 2010 12:14 pm
by Alex
Hi again,
so you finally made it work without noticing what actually happened. It is a very common issue with Python and its strong dependency on text indention. What Florian suggests makes plenty of sense.
Internal Python tab width is 8 spaces.
We have added an option in preferences to "Expand tabs". If enabled, tabs are converted to spaces at the moment of script execution. Unfortunately, even if enabled, it is not working with the Master script at this moment (bug).
We would like to add some visual feedback to show the user tabs and spaces at the beginning of lines, but we still have to think about it.
Regardless the tabs/spaces hell, if I have some code like this: (| means end of line)
Code: Select all
# function|
def function():|
|
instruction|
more instructions|
and more|
|
and more|
#comment|
and more|
|
# another_function|
def another_function():|
pass|
|
I would try to make it look like this as much as possible:
Code: Select all
# function|
def function():|
|
instruction|
more instructions|
and more|
|
and more|
#comment|
and more|
|
# another_function|
def another_function():|
pass|
|
I would definitely indent blank lines and comments too.
That's the only "unusual" thing I could find in your script. Everything else looks completely right.
Re: Scripting: Error at line nr XX...but no error???
Posted: Tue Nov 09, 2010 1:08 pm
by DragonsSpirit
hm..ok. I thank both of you, Ill try again.
cya