If you have a problem or need to report a bug please email : support@dsprobotics.com
There are 3 sections to this support area:
DOWNLOADS: access to product manuals, support files and drivers
HELP & INFORMATION: tutorials and example files for learning or finding pre-made modules for your projects
USER FORUMS: meet with other users and exchange ideas, you can also get help and assistance here
NEW REGISTRATIONS - please contact us if you wish to register on the forum
Users are reminded of the forum rules they sign up to which prohibits any activity that violates any laws including posting material covered by copyright
how to get rid of ruby error for nil class on start
8 posts
• Page 1 of 1
how to get rid of ruby error for nil class on start
On several occasions, my ruby modules have nil inputs when starting, which produces some errors (see on load and when clicking). See on attached example. My question - how to get rid of this problem from within ruby module?
- Attachments
-
- rubyerror.fsm
- (594 Bytes) Downloaded 869 times
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
Feel free to donate. Thank you for your contribution.
- tester
- Posts: 1786
- Joined: Wed Jan 18, 2012 10:52 pm
- Location: Poland, internet
Re: how to get rid of ruby error for nil class on start
Maybe connect an afterload trigger there?
- adamszabo
- Posts: 667
- Joined: Sun Jul 11, 2010 7:21 am
Re: how to get rid of ruby error for nil class on start
It's not the matter of afterload trigger.
What I attached - is an exmple schematic of what happens when such ruby module receives nil value.
What I need, is to avoid such problems from within ruby module/code.
What I attached - is an exmple schematic of what happens when such ruby module receives nil value.
What I need, is to avoid such problems from within ruby module/code.
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
Feel free to donate. Thank you for your contribution.
- tester
- Posts: 1786
- Joined: Wed Jan 18, 2012 10:52 pm
- Location: Poland, internet
Re: how to get rid of ruby error for nil class on start
just call methodes when no of the required parameters are nil,
avoid nil values to happen,
or set nils to valid values
avoid nil values to happen,
or set nils to valid values
-
Nubeat7 - Posts: 1347
- Joined: Sat Apr 14, 2012 9:59 am
- Location: Vienna
Re: how to get rid of ruby error for nil class on start
What Nubeat says, esp. the last one. NIL informs you that you try to work with a non-existing value. It's an essential tool to avoid errors. So test for nil, before proceeding. Typical examples:
Adam has a point though. If you have inputs that can be nil, but you don't want them to be nil (because your code doesn't even recognize nil), you should indeed set them to values after start/duplicating, etc.
- Code: Select all
def mysquare(value)
return value**2 unless value.nil?
end
def count_existing(value)
mycounter += 1 if value
end
def accessing_an_input
return if @ins[0].nil?
##safely use first input from here on##
end
Adam has a point though. If you have inputs that can be nil, but you don't want them to be nil (because your code doesn't even recognize nil), you should indeed set them to values after start/duplicating, etc.
"There lies the dog buried" (German saying translated literally)
- tulamide
- Posts: 2714
- Joined: Sat Jun 21, 2014 2:48 pm
- Location: Germany
Re: how to get rid of ruby error for nil class on start
Nubeat7 wrote:just call methodes when no of the required parameters are nil,
avoid nil values to happen,
or set nils to valid values
It's not that simple. On several occasions, some things are reset, and nil out with trigger passes through. It's one of these monster-bigbig projects...
Right now I'm using something like this:
--------------------------------
def event(in_id, val)
if in_id == "trigger"
anything else
end
end
--------------------------------
where trigger comes from a separate input.
What I need to add is just something, that detects if inputs are nil - and instead of producing error code - just sends nil (with trigger or without it - passive way) through/to associated outputs.
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
Feel free to donate. Thank you for your contribution.
- tester
- Posts: 1786
- Joined: Wed Jan 18, 2012 10:52 pm
- Location: Poland, internet
Re: how to get rid of ruby error for nil class on start
in general i mostly avoid nil, except for sending some triggersignals to an output...
the handling of nils can be very different, so its not that easy to give an "always working solution"
but mostly its some asking if its nil then react like tulamides examples
but you can also work the other way and only do something if a value is a specific value, so instead of asking for nil you can ask for string or float before doing something
btw. sometimes its also important to make a difference between empty and nil..
the handling of nils can be very different, so its not that easy to give an "always working solution"
but mostly its some asking if its nil then react like tulamides examples
but you can also work the other way and only do something if a value is a specific value, so instead of asking for nil you can ask for string or float before doing something
btw. sometimes its also important to make a difference between empty and nil..
-
Nubeat7 - Posts: 1347
- Joined: Sat Apr 14, 2012 9:59 am
- Location: Vienna
Re: how to get rid of ruby error for nil class on start
Nil errors were always the most annoying part of FSRuby.
To fix this issue in all major Ruby jobs, i came up with this method a few
years ago, to silence any threat from a nil error 'stealth attack'.
Create the following code block after the 'def init' section.
def nil errors
Insert your condoms and devices of protection here
end
Then just write " nil errors " at the start of every code block.
Works great for me.But thats just me, and therefore has no real meaning.
Have a nice day!
To fix this issue in all major Ruby jobs, i came up with this method a few
years ago, to silence any threat from a nil error 'stealth attack'.
Create the following code block after the 'def init' section.
def nil errors
Insert your condoms and devices of protection here
end
Then just write " nil errors " at the start of every code block.
Works great for me.But thats just me, and therefore has no real meaning.
Have a nice day!
BV MUSIC SYDNEY AUSTRALIA..Songwriting and Software development
Headquartershttps://www.bvmusicsydneyaustralia.com/
Spotifyhttps://open.spotify.com/artist/7JO8QM40mVmHb7pAwKPJi0
Donatationhttps://www.paypal.com/donate/?hosted_button_id=HEUR8R7K8GZ4L
Headquartershttps://www.bvmusicsydneyaustralia.com/
Spotifyhttps://open.spotify.com/artist/7JO8QM40mVmHb7pAwKPJi0
Donatationhttps://www.paypal.com/donate/?hosted_button_id=HEUR8R7K8GZ4L
- billv
- Posts: 1157
- Joined: Tue Aug 31, 2010 3:34 pm
- Location: Australia
8 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 70 guests