Notifications
Clear all

Error while modding


Loki999
(@loki999)
Master Chief Registered
Joined: 11 years ago
Posts: 165
Topic starter  

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"] bad argument #1 to 'pairs' (table expected, got nil)

stack traceback:

[C]: in function 'pairs'

[string "modules/TradeShips.lua"] in function 'getSystem'

[string "modules/TradeShips.lua"] in function 'getSystemAndJump'

[string "modules/TradeShips.lua"] in function 'cb'

[string "libs/00-Event.lua"] in function '?'

[string "libs/00-Event.lua"] 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']) do

Why could it be getting nil when table expected, and ok, assuming an empty table, then why does it not handle it gracefully?

Thoughts?


Quote
Loki999
(@loki999)
Master Chief Registered
Joined: 11 years ago
Posts: 165
Topic starter  

@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.

http://dl.dropbox.com/u/29921927/TradeShips.lua


ReplyQuote
Loki999
(@loki999)
Master Chief Registered
Joined: 11 years ago
Posts: 165
Topic starter  

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.


ReplyQuote
Loki999
(@loki999)
Master Chief Registered
Joined: 11 years ago
Posts: 165
Topic starter  

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: 55

Error: [string "modules/TradeShips.lua"] attempt to index local 'trader' (a nil value)

stack traceback:

[string "modules/TradeShips.lua"] in function 'getNearestStarport'

[string "modules/TradeShips.lua"] in function <[string "modules/TradeShips.lua"]:675>

I'll give my left ball that this is also a bug with existing code <img src="' http://spacesimcentral.com/forum/public/style_emoticons//icon_e_biggrin.gi f"' class='bbc_emoticon' alt=':-D' />


ReplyQuote
Brianetta
(@brianetta)
Commander Registered
Joined: 13 years ago
Posts: 863
 

Looks like a ship physically went missing, without the script noticing.


ReplyQuote
Loki999
(@loki999)
Master Chief Registered
Joined: 11 years ago
Posts: 165
Topic starter  

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.


ReplyQuote
Brianetta
(@brianetta)
Commander Registered
Joined: 13 years ago
Posts: 863
 

"~= nil" is one of those things I never expect to see in Lua. Looks like that script's going to need some review.


ReplyQuote
Loki999
(@loki999)
Master Chief Registered
Joined: 11 years ago
Posts: 165
Topic starter  

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?


ReplyQuote
Brianetta
(@brianetta)
Commander Registered
Joined: 13 years ago
Posts: 863
 

if object then

print('Object exists.')

else

print('It doesn't exist.')

end


ReplyQuote
Loki999
(@loki999)
Master Chief Registered
Joined: 11 years ago
Posts: 165
Topic starter  

Interesting. I'll have to pick your brains on IRC as to why you feel this is an issue.


ReplyQuote
Brianetta
(@brianetta)
Commander Registered
Joined: 13 years ago
Posts: 863
 

Sure.


ReplyQuote