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
Impressively Grand Sub-Admiral
Impressively Grand Sub-Admiral
Posts: 4830
Joined: Tue Jan 21, 2014 10:37 pm
Location: Writing more OXPs, because the world needs more OXPs.

Error "Tried to init array with nil object"

Post by phkb »

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: 2577
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 »

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

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

Post by another_commander »

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: 2577
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 »

Working well at me, thank you!
Post Reply