Hey, I am a college student, I'm rewritting a psychology program from
Chipmunk basic to ruby, It was all going fine until I had to write the
scoring code. Basically what happens is a bunch of subroutines are
called randomly and then the answers are stored in a global variable
$scores ( which is initialized via $score = Array.new(6) {Array.new(3)
{0}} ). Usually I get about a few in, usually the second falsecat (the
code I posted on paste bin along with the scoring subroutine) I get an
error message:
exp.rb:93:in `scoring': undefined method `[]' for nil:NilClass
(NoMethodError)
from exp.rb:105:in `falsecatsub'
from exp.rb:177
from exp.rb:173:in `each'
from exp.rb:173
But I have no idea what it means! I thought maybe my numbering variable
was broken and returning nothing hence the [] or that time had a naming
conflict but I tried all that and... nothing. Here is the code! http://pastebin.com/yMNbTyVF Have fun, and thanks!
What that error means is that you are calling method on nil. Inside
scoring the only references to are $score[n] so that means that either
$score is nil or that it doesn't have any element at position n. You could
try to put this line
p $score
at the beginning of the scoring method to make sure what you have there.
Jesus.
···
El 22/09/2011 23:50, "Roland S." <xidusmon@gmail.com> escribió:
Hey, I am a college student, I'm rewritting a psychology program from
Chipmunk basic to ruby, It was all going fine until I had to write the
scoring code. Basically what happens is a bunch of subroutines are
called randomly and then the answers are stored in a global variable
$scores ( which is initialized via $score = Array.new(6) {Array.new(3)
{0}} ). Usually I get about a few in, usually the second falsecat (the
code I posted on paste bin along with the scoring subroutine) I get an
error message:
exp.rb:93:in `scoring': undefined method `' for nil:NilClass
(NoMethodError)
from exp.rb:105:in `falsecatsub'
from exp.rb:177
from exp.rb:173:in `each'
from exp.rb:173