KirkMcDonald / factorio-tools

Tools dealing with the game Factorio.
54 stars 29 forks source link

Error: [string <mod_file_name>]:<n>: attempt to index a nil value (field 'startup') #8

Open eduran84 opened 5 years ago

eduran84 commented 5 years ago

I really love your calculator! I've just discovered the offline version which imports local mod data and would like to use it.

If I do, I see error messages like: [string "bobassembly_0.17.2/prototypes/assembly-electr..."]:1: attempt to index a nil value (field 'startup') or [string "BigDrills_0.5.4/prototypes/tech/tech.lua"]:47: attempt to call a nil value (global 'unpack')

The relevant lua code from said mods looks like this: if settings.startup["bobmods-assembly-electronicmachines"].value == true then and prerequisites = {"logistics-2", "bucket-wheel-excavator", "advanced-material-processing-2", unpack(preMK2 or {})},

If I start the calculator with an empty mod dir everything works fine. As do most mods, except those that reference settings.startup or try to call unpack.

Factorio version: 0.17.28 Calculator version: 0.3 binary for windows Mods causing error messages: bobassembly_0.17.2.zip, BigDrills_0.5.4.zip

Is there anything I can do to fix this issue on my end?

RustyBlade64 commented 5 years ago

The first of these two problems should be resolved by KirkMcDonald/FactorioLoaderLib#7.

The second one I cannot reproduce. Given that unpack has been moved to table.unpack in Lua 5.2 and the fact that there is a backward compatibility flag that can be enabled somewhere I suspect this might be a platform dependent issue:

Function unpack was moved into the table library and therefore must be called as table.unpack.

https://www.lua.org/manual/5.2/manual.html#8.2

You're probably embedding Lua as source, not as a pre-built library. In this case, you have probably not enabled backward compatibility.

By default, the command line interpreter is built with backward compatibility, hence the difference you see

https://stackoverflow.com/questions/25794364/lua-trouble-attempt-to-call-global-unpack-a-nil-value

I would guess Factorio has this backward compatibility flag set, but KirkMcDonald/golua in the windows binary probably has not.

Magos commented 4 years ago

I'm also experiencing the startup issue and it does indeed appear to be an issue with load order. The minimal setup to reproduce that I've found:

  1. Clear all mods from Factorio mod manager.
  2. Install AngelBob and its transitive dependencies.
  3. Open factoriocalc 0.3
  4. attempt to index nil error happens in [boblibrary_0.17.5/resource-generator.lua]. Editing this file shows it's masking similar errors further along in the dependency graph.

This is on Windows. I really love this calculator and having the option to use it to manage the sheer complexity of Angels + Bob's would be a great help. factorio-current.log