Error while modding

Pioneer is an open-ended space adventure game. Explore the galaxy, make your fortune trading between systems, or work for the various factions fighting for power, freedom or self-determination.
Homepage: http://pioneerspacesim.net/
IRC: http://pioneerspacesim.net/irc
Downloads: https://pioneerspacesim.net/page/download/
Post Reply
Loki999
Private
Posts: 165
Joined: Wed Oct 31, 2012 7:27 am

Error while modding

Post by Loki999 »

Yeah, ok, so while modding i'm liable to break something, but this is throwing an error in a function I haven't touched so its got me scratching my head a little.Its the mod i'm working on to increase traffic in the system. Happens quite quickly in systems where more ships will be spawned (sometimes almost instantly), especially on new game in Sol or New Hope.I'm wondering if it could be a problem with the game but rare, because not usually so many ships flying around, and its just more likely to be triggered when i'm spawning lots of traders.Anyway, here is the output of stderr:
Quote:
Error: Lua custom Systems definition: Surface starport is underwater (height not greater than 0.0) and has been automatically relocated. Please move the starport to another location by changing latitude and longitude fields.Surface starport name: New Hope, Body name: New Hope, In sector: x = 1, y = -1, z = -1.Error: [string "modules/TradeShips.lua"]:230: bad argument #1 to 'pairs' (table expected, got nil)stack traceback:[C]: in function 'pairs'[string "modules/TradeShips.lua"]:230: in function 'getSystem'[string "modules/TradeShips.lua"]:281: in function 'getSystemAndJump'[string "modules/TradeShips.lua"]:590: in function 'cb'[string "libs/00-Event.lua"]:32: in function '?'[string "libs/00-Event.lua"]:182: in function <[string "libs/00-Event.lua"]:177>
The actual line which it is referencing (line 230, getSystem) is: for cargo, count in pairs(trade_ships[ship]['cargo']) doWhy could it be getting nil when table expected, and ok, assuming an empty table, then why does it not handle it gracefully?Thoughts?
Loki999
Private
Posts: 165
Joined: Wed Oct 31, 2012 7:27 am

RE: Error while modding

Post by Loki999 »

@robn - as discussed my modified TradeShips.lua for Alpha 28.Let me know if you spot anything. Ill try the stuff we discussed on IRC later.[url]http://dl.dropbox.com/u/29921927/TradeShips.lua[/url]
Loki999
Private
Posts: 165
Joined: Wed Oct 31, 2012 7:27 am

RE: Error while modding

Post by Loki999 »

Ah, your suggestion may just have hit the nail on the head robn.
Quote:
trade_ships[ship] = {status = 'inbound',ship_name = ship_name,cargo = {},}
Added the line in red straight after ship spawn, didn't happen at all on an extended play in New Hope.Ill run more tests, see if it holds up.Altthough, as a side note, while watching ships come and go, i watched a rather stupid pilot fly into a Lynx Bulk Carrier while trying to dock. Second stage to the mod hopefully will reduce this insanity as Bulk Carriers will not always be parked so close to stations.
Loki999
Private
Posts: 165
Joined: Wed Oct 31, 2012 7:27 am

RE: Error while modding

Post by Loki999 »

Hehe... i keep finding errors in code due to my increased trade ships. The last one seemed to be a problem that was always there, just probably very rarely encountered.Now i got this one.
Quote:
savefile version: 55Error: [string "modules/TradeShips.lua"]:202: attempt to index local 'trader' (a nil value)stack traceback:[string "modules/TradeShips.lua"]:202: in function 'getNearestStarport'[string "modules/TradeShips.lua"]:677: in function <[string "modules/TradeShips.lua"]:675>
I'll give my left ball that this is also a bug with existing code <img src="'[url]http://spacesimcentral.com/forum/public/style_emoticons//icon_e_biggrin.gif[/url] class='bbc_emoticon' alt=':-D' />
Brianetta
Private
Posts: 863
Joined: Sun Apr 03, 2011 6:12 pm

RE: Error while modding

Post by Brianetta »

Looks like a ship physically went missing, without the script noticing.
Loki999
Private
Posts: 165
Joined: Wed Oct 31, 2012 7:27 am

RE: Error while modding

Post by Loki999 »

Yup. Interesting it is highly unlikely that a ship disappeared between the function being called and the actual function running, which is a very tiny window. The function that calls it actually makes a check to see if ~= nil, so it should be valid. So guessing the trade_ships table says it exists, but in reality, it doesn't.Well, its an edge case for now, and so far not reproducible, so ill let it lie unless it happens again.
Brianetta
Private
Posts: 863
Joined: Sun Apr 03, 2011 6:12 pm

RE: Error while modding

Post by Brianetta »

"~= nil" is one of those things I never expect to see in Lua. Looks like that script's going to need some review.
Loki999
Private
Posts: 165
Joined: Wed Oct 31, 2012 7:27 am

RE: Error while modding

Post by Loki999 »

Hehe, robn already said that after we discussed the previous error (spaghetti code was his comment) and due to lack of initialization of the cargo var after object was created.What do you recommend then to test if an object exists?
Brianetta
Private
Posts: 863
Joined: Sun Apr 03, 2011 6:12 pm

RE: Error while modding

Post by Brianetta »

if object thenprint('Object exists.')elseprint('It doesn't exist.')end
Loki999
Private
Posts: 165
Joined: Wed Oct 31, 2012 7:27 am

RE: Error while modding

Post by Loki999 »

Interesting. I'll have to pick your brains on IRC as to why you feel this is an issue.
Brianetta
Private
Posts: 863
Joined: Sun Apr 03, 2011 6:12 pm

RE: Error while modding

Post by Brianetta »

Sure.
Post Reply

Return to “Pioneer”