Error: undefined method '+' for nil:NilClass
-
Hi there
I got a new notebook and now SU8 is finally working. I wanted to script something in Sp3, but it didn't work right. There was an error message, which told me "undefined method 'atan2' for nil:NilClass". So I made a simple testing program and even that didn't work. Here's the code:
if frame==0 $a=1 $b=2 end $c=$a+$b puts "1+2=#{$c}"
it should just handle some variables and send the result to the ruby-console, but by hitting play I always got this error message:
"undefined method '+' for nil:NilClass"
Even if I used local variables, it didn't change anything. By using getVar and setVar it worked, but the result was always 0.00
What's going wrong? -
Don't use $ global variables.
There is rarely a reason that can't be side stepped - use a, b and c.
If frame is not 0 then a or b are not set to anything, so the error is correct because nil + nil doesn't work ! -
Ok, now this works.
Now I have another problem: I can't read out the frame in the scripted box.
if i do so, an error message appears.
When I write something likeMath.sin(frame/100.00)
in the controller of a servo, it works, but if I write
setVar("a",frame/100.00)
and into the controller
getVar("a")
the error message occurs.
That's really odd...edit: It seems, that my old SP models work well, but if I copy the code into a new Scripted-box ob an object, it doesn't work anymore. Maybe I should get an older Version of SP?
Advertisement