Error "Tried to init array with nil object"

For test results, bug reports, announcements of new builds etc.

Moderators: winston, another_commander, Getafix

Post Reply
User avatar
phkb
Commodore
Commodore
Posts: 2433
Joined: Tue Jan 21, 2014 10:37 pm
Location: [p]laying [h]ard and [k]icking [b]utt somewhere in G7...

Error "Tried to init array with nil object"

Post by phkb » Wed Oct 28, 2015 11:04 pm

I'm running this code to determine if a ship has missiles:

Code: Select all

if (ship.missiles) {
   ...some code to run when there are missiles...
}
However, if there are no missiles installed I get this error:

Code: Select all

Error: Native exception: Tried to init array with nil object
I tried doing if (ship.missiles.length > 0) and even adding a check for missileCapacity but neither solution worked. In the end I put the code into a try/catch block to work around the issue.

User avatar
Norby
---- E L I T E ----
---- E L I T E ----
Posts: 2543
Joined: Mon May 20, 2013 9:53 pm
Location: Budapest, Hungary (Mainly Agricultural Democracy, TL10)
Contact:

Re: Error "Tried to init array with nil object"

Post by Norby » Wed Oct 28, 2015 11:23 pm


another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 5397
Joined: Wed Feb 28, 2007 7:54 am

Re: Error "Tried to init array with nil object"

Post by another_commander » Thu Oct 29, 2015 2:57 pm

Thanks for the reports guys. I have pushed a tentative fix on github. Can you please check and confirm that it works without issues or side effects?

User avatar
Norby
---- E L I T E ----
---- E L I T E ----
Posts: 2543
Joined: Mon May 20, 2013 9:53 pm
Location: Budapest, Hungary (Mainly Agricultural Democracy, TL10)
Contact:

Re: Error "Tried to init array with nil object"

Post by Norby » Fri Oct 30, 2015 11:47 am

Working well at me, thank you!

Post Reply