Jump to content

resourcetrader.lua Is Using Table.Insert Wrong


Shrooblord

Recommended Posts

Hiya, stumbled across something in the console whenever I load the game inside a Sector with Resource Depots, as well as periodically while inside these Sectors.

 

See the screenshot.

 

This problem is coming from the ResourceDepot.secure() function. I went into resourcetrader.lua where this error originates, and added a print command so I could see what was being passed into table.insert():

 

function ResourceDepot.secure()
    data = {}
    for k, v in pairs(stock) do
        print("k="..tostring(k).."; v="..tostring(v))   --SHR SU
        table.insert(data, k, v)
    end

    table.insert(data, shortageMaterial or -1)
    table.insert(data, shortageAmount or -1)
    table.insert(data, shortageTimer)

    return data
end

 

My only change is that print line.

 

In the screenshot, you can see the result of the output. The value of the variable k is reported as being  the string currentProductions, while table.insert() is expecting the type number. So why does table.insert() expect a number? Turns out someone on StackOverflow had the same question.

 

Apparently, if you use the three-argument version of table.insert() like is being done here, the second argument is expected to be a number. Hence the error when that string is passed to it instead.

 

As you can probably all tell from still being able to do business with Resource Depots in your builds of the game, this seems like a non-critical bug. However, console is complaining about it and also it's... well, it's a bug, so I'm guessing it needs to be squashed.

 

Happy coding! ^^'

Link to comment
Share on other sites

  • 2 weeks later...

Some ppl in the server I'm playing in reported issues with Resource depots. They said they were unable to sell iron to those depots despite they had enough iron, they had enough reputation and they were close enough.

I have seen about 5 players with that problem, is your post related to that?

Link to comment
Share on other sites

I'm not sure. The secure function is called every time a server save is triggered, which stores data so that in the event of a load, all the data can be restored (via the restore function). Many scripts have these functions, as you'll know if you look at a couple of scripts yourself.

 

There seems to be an issue storing the variable currentProductions, whatever that means. It may have to do with some kind of restocking mechanic that Resource Depots have? I'm not an expert on RDs.

 

It shouldn't affect the trading functionality of RDs, but who knows how bugs multiply throughout the functionality of code if left unchecked.

Link to comment
Share on other sites

I couldn't reproduce this error on a newly created 0.15.8 (0.15.7 would be the same, since the file didn't change) Galaxy. And the code has nothing in it that can produce the key "currentProductions".

 

Personally I think this is either some mod badly interacting or something that got ported from an older version of the file.

 

@Shrooblord, Since I can't reproduce it, would you be so kind and add the following in line 55:

printTable(data)

and post the result?

Link to comment
Share on other sites

Certainly. However, after updating to your newest version of the OoSP Mod, it seems to have migrated to solely your resourcetrader.lua script files, and has disappeared from the vanilla lua files.

 

Here's the relevant part of my server log where the data is printed:

2018-02-04 12-26-01| k: currentProductions -> v: table: 00000000176265C0
2018-02-04 12-26-01| k: tradingData -> v: table: 0000000017626A20
2018-02-04 12-26-01|   k: policies -> v: table: 0000000017626D40
2018-02-04 12-26-01|     k: sellsSuspicious -> v: false
2018-02-04 12-26-01|     k: sellsIllegal -> v: false
2018-02-04 12-26-01|     k: buysIllegal -> v: false
2018-02-04 12-26-01|     k: buysSuspicious -> v: false
2018-02-04 12-26-01|     k: sellsStolen -> v: false
2018-02-04 12-26-01|     k: buysStolen -> v: false
2018-02-04 12-26-01|   k: buyPriceFactor -> v: 1
2018-02-04 12-26-01|   k: activelyRequest -> v: false
2018-02-04 12-26-01|   k: buyFromOthers -> v: true
2018-02-04 12-26-01|   k: deliveredStations -> v: table: 0000000017625EE0
2018-02-04 12-26-01|   k: activelySell -> v: false
2018-02-04 12-26-01|   k: soldGoods -> v: table: 0000000017626AC0
2018-02-04 12-26-01|   k: sellToOthers -> v: true
2018-02-04 12-26-01|   k: boughtGoods -> v: table: 0000000017626DE0
2018-02-04 12-26-01|   k: sellPriceFactor -> v: 1
2018-02-04 12-26-01|   k: deliveringStations -> v: table: 0000000017626520
2018-02-04 12-26-01| could not execute function 'ResourceDepot.onRestoredFromDisk' in '"data/scripts/entity/merchants/resourcetrader.lua"':
2018-02-04 12-26-01| .\mods/oosp/scripts/entity/merchants/resourcetrader.lua:150: attempt to perform arithmetic on field '?' (a nil value)
2018-02-04 12-26-01| stack traceback:
2018-02-04 12-26-01| 	.\mods/oosp/scripts/entity/merchants/resourcetrader.lua:150: in function <.\mods/oosp/scripts/entity/merchants/resourcetrader.lua:142>
2018-02-04 12-26-01| 
2018-02-04 12-26-01| scheduled save for sector (-81:-161), 0xa64e040, entities: 240
2018-02-04 12-26-01| could not execute function 'ResourceDepot.secure' in '"data/scripts/entity/merchants/resourcetrader.lua"':
2018-02-04 12-26-01| .\mods/oosp/scripts/entity/merchants/resourcetrader.lua:78: bad argument #2 to 'insert' (number expected, got string)
2018-02-04 12-26-01| stack traceback:
2018-02-04 12-26-01| 	[C]: in function 'insert'
2018-02-04 12-26-01| 	.\mods/oosp/scripts/entity/merchants/resourcetrader.lua:78: in function <.\mods/oosp/scripts/entity/merchants/resourcetrader.lua:75>
2018-02-04 12-26-01| 
2018-02-04 12-26-01| saving sector (-81:-161)
2018-02-04 12-26-02| player events roughly every 16.57 minutes
2018-02-04 12-26-02| sector (-81:-161) saved to "C:\Users\Shrooblord\AppData\Roaming\Avorion\galaxies\The Shroobiverse\sectors\-81_-161"
2018-02-04 12-26-02| could not execute function 'ResourceDepot.secure' in '"data/scripts/entity/merchants/resourcetrader.lua"':
2018-02-04 12-26-02| .\mods/oosp/scripts/entity/merchants/resourcetrader.lua:78: bad argument #2 to 'insert' (number expected, got string)
2018-02-04 12-26-02| stack traceback:
2018-02-04 12-26-02| 	[C]: in function 'insert'
2018-02-04 12-26-02| 	.\mods/oosp/scripts/entity/merchants/resourcetrader.lua:78: in function <.\mods/oosp/scripts/entity/merchants/resourcetrader.lua:75>
2018-02-04 12-26-02| 
2018-02-04 12-26-02| Player Shrooblord moved to sector (-81:-161) server time taken for change: 20ms
2018-02-04 12-26-02| scheduled save for sector (222:-189), 0xf79d850, entities: 306
2018-02-04 12-26-02| saving sector (222:-189)
2018-02-04 12-26-02| sector (222:-189) saved to "C:\Users\Shrooblord\AppData\Roaming\Avorion\galaxies\The Shroobiverse\sectors\222_-189"
2018-02-04 12-26-02| scheduled save for sector (-81:-161), 0xa64e040, entities: 240
2018-02-04 12-26-02| could not execute function 'ResourceDepot.secure' in '"data/scripts/entity/merchants/resourcetrader.lua"':
2018-02-04 12-26-02| .\mods/oosp/scripts/entity/merchants/resourcetrader.lua:78: bad argument #2 to 'insert' (number expected, got string)
2018-02-04 12-26-02| stack traceback:
2018-02-04 12-26-02| 	[C]: in function 'insert'
2018-02-04 12-26-02| 	.\mods/oosp/scripts/entity/merchants/resourcetrader.lua:78: in function <.\mods/oosp/scripts/entity/merchants/resourcetrader.lua:75>

 

Thanks for looking into this.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...