Forum: Ruby undefined method error

4c1b1c63b81fe7c9f09128674b7c2da6?d=identicon&s=25 Kenny Andrews (puef)
on 2014-07-17 14:19
so im trying to compile a bot for a video game and it gives me undefined
method error for a certain script and i have no idea who to fix it.

im getting this build_tools/process_files.rb:70:in `generate_version':
undefined method `[]' for nil:NilClass (NoMethodError)
  from build_tools/process_files.rb:61:in `generate_build_information'
  from build_tools/process_files.rb:142:in `block in <main>'
  from build_tools/process_files.rb:55:in `initialize'
  from build_tools/process_files.rb:139:in `new'
  from build_tools/process_files.rb:139:in `<main>'
build_tools/process_files.rb Starting...
Command /bin/sh failed with exit code 1


the piece of code is

def generate_version
            game_version =
                (@build_information[:kind] == "CVS") ?
                    %x("#{TOP_LEVEL}/batch/make/version"
"#{TOP_LEVEL}").chomp :
                    File.read("#{TOP_LEVEL}/src/macosx/config_common.h.in").scan(/"#define
VERSION "(.*)"/)[0][0]
                                                                             @build_information[:version]
= game_version
                                                                             end

if anyone could help that was be awesome.
5c4e55b92169c16ce2ca8fd75318eded?d=identicon&s=25 David Unric (dunric)
on 2014-07-17 15:29
You didn't posted where is the row Nr. 70 but from the code I'd suspect
the issue is with @build_information instance variable is not
initialized - ie its value is nil, therefore sending `[]' method fails
with exception.
4c1b1c63b81fe7c9f09128674b7c2da6?d=identicon&s=25 Kenny Andrews (puef)
on 2014-07-17 15:39
oh sorry line 70 is
File.read("#{TOP_LEVEL}/src/macosx/config_common.h.in").scan(/"#define
VERSION "(.*)"/)[0][0]
14b5582046b4e7b24ab69b7886a35868?d=identicon&s=25 Joel Pearson (virtuoso)
on 2014-07-17 20:53
Test the output of this:
File.read("#{TOP_LEVEL}/src/macosx/config_common.h.in").scan(/"#define
VERSION "(.*)"/)

It looks like it isn't finding any matches, so when you try to access
the object in index zero with [0][0], it tells you that #[] is not
defined on NilClass, because there's nothing in the array.
5c4e55b92169c16ce2ca8fd75318eded?d=identicon&s=25 David Unric (dunric)
on 2014-07-17 21:08
So it's clear now. File <top level>/src/macosx/config_common.h.in does
not contain expected pattern "#define VERSION "(.*)" .

First I'd make sure whether all double-quotes in /"#define VERSION
"(.*)"/ are correct. I'd bet the first one before #define is accidental
and may need to be removed.
Second open the `common.h.in' file in an editor and look for a row
containing VERSION macro definition and check the current format and
adjust the regexp pattern accordingly. If in troubles you may paste the
corresponding line here.
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.