Notifications
Clear all

To all SSC Station occupants

Thank you for the donations over the past year (2024), it is much appreciated. I am still trying to figure out how to migrate the forums to another community software (probably phpbb) but in the meantime I have updated the forum software to the latest version. SSC has been around a while so their is some very long time members here still using the site, thanks for making SSC home and sorry I haven't been as vocal as I should be in the forums I will try to improve my posting frequency.

Thank you again to all of the members that do take the time to donate a little, it helps keep this station functioning on the outer reaches of space.

-D1-

Error while modding

(@loki999)
Estimable Member

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']) 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
Topic starter Posted : November 15, 2012 11:27
(@loki999)
Estimable Member

@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
Topic starter Posted : November 16, 2012 04:19
(@loki999)
Estimable Member

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
Topic starter Posted : November 16, 2012 09:29
(@loki999)
Estimable Member

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"]: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="' http://spacesimcentral.com/forum/public/style_emoticons//icon_e_biggrin.gi f"' class='bbc_emoticon' alt=':-D' />

ReplyQuote
Topic starter Posted : November 17, 2012 11:00
(@brianetta)
Prominent Member

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

ReplyQuote
Posted : November 17, 2012 12:46
(@loki999)
Estimable Member

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
Topic starter Posted : November 17, 2012 22:23
(@brianetta)
Prominent Member

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

ReplyQuote
Posted : November 18, 2012 01:52
(@loki999)
Estimable Member

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
Topic starter Posted : November 18, 2012 02:32
(@brianetta)
Prominent Member

if object then

print('Object exists.')

else

print('It doesn't exist.')

end

ReplyQuote
Posted : November 18, 2012 03:26
(@loki999)
Estimable Member

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

ReplyQuote
Topic starter Posted : November 18, 2012 03:31
(@brianetta)
Prominent Member

Sure.

ReplyQuote
Posted : November 18, 2012 03:47