undefined method `*' for nil:NilClass

For general discussion related FlowStone
Post Reply
tor
Posts: 114
Joined: Fri Sep 24, 2010 5:54 pm

undefined method `*' for nil:NilClass

Post by tor »

So what am I doin wrong here?

Code: Select all

rectbounds3=[@width*0.5-@ledw*0.5,@hight*0.5-@ledh*0.5,@ledw,@ledh]
fade3=LinearGradientBrush.new rectbounds3,@c3,@c4,45,true
v.drawRoundRect fade3,rectbounds3,@round

NoMethodError: undefined method `*' for nil:NilClass
tor
Posts: 114
Joined: Fri Sep 24, 2010 5:54 pm

Re: undefined method `*' for nil:NilClass

Post by tor »

I found if I move the mulitpliers in front of the @ floats like this: 0.5*@hight-0.5*@ledh
I get this error instead: TypeError: (in method 'draw'): nil cant be coerced into Float
Button.fsm
(1.75 KiB) Downloaded 1074 times

And after some googling I learned that in this case it is most likely that @ledh and @ledw is nil. Question is why?
When I edit the values in the green floats outside the code that feed theese two values the error disappears while i write a new value. But the moment i press enter to set the value, the error is back.
User avatar
trogluddite
Posts: 1730
Joined: Fri Oct 22, 2010 12:46 am
Location: Yorkshire, UK

Re: undefined method `*' for nil:NilClass

Post by trogluddite »

tor wrote:@hight

should be

Code: Select all

@height

I do this 50 times a day! If you don't spell a variable right, it counts as undeclared and returns 'nil'.
All schematics/modules I post are free for all to use - but a credit is always polite!
Don't stagnate, mutate to create!
tor
Posts: 114
Joined: Fri Sep 24, 2010 5:54 pm

Re: undefined method `*' for nil:NilClass

Post by tor »

dang... I just could not see it. Checked it over and over and over :?

THANK YOU TROG :)

This is probably going to be one of my biggest challenges with a language like Ruby, getting the spelling right.
Post Reply