AAI Industry

The industry part of Advanced Autonomous Industries. Adds motors, powered offshore pumps, burner labs, and more. Alters tech and recipes. Additional features will be added gradually. Other AAI mods are not required. Works with Bobs and Angels.
16 days ago
0.15 - 0.17
111776

b Crash with Angel's Refining

- 4 months ago
(updated 4 months ago)

A message I left on the Angel's Mods bug reports that I figured should be reported here as someone reported that this is a conflict with AAI Industries:
https://forums.factorio.com/viewtopic.php?f=185&t=25468&p=422592#p422592

The full error is:
136.158 Error ModManager.cpp:1294: Failed to load mod "angelsrefining": __angelsrefining__/prototypes/override-> functions.lua:529: table index is nil stack traceback: __angelsrefining__/prototypes/override-functions.lua:529: in function 'execute' __angelsrefining__/data-updates.lua:9: in main chunk

Of the code at the reported location being:
lua if tech.prerequisites then to_remove = {} for pk, prereq in pairs(tech.prerequisites) do local new = substitution_table.technologies[prereq] if new then tech.prerequisites[pk] = new end if modifications and modifications[prereq] == false then to_remove[pk] = true end end for pk = #tech.prerequisites, 1, -1 do if to_remove[pk] then table.remove(tech.prerequisites, pk) else dup_table[tech.prerequisites[pk]] = true -- This is line 529 end end end
Of that line pk is the number value of 1, and tech is the value of:
lua { effects = { { recipe = "logistic-science-pack", type = "unlock-recipe" } }, icon = "__base__/graphics/technology/logistic-science-pack.png", icon_size = 128, localised_description = { "technology-description.logistic-science-pack" }, localised_name = { "technology-name.logistic-science-pack" }, name = "logistic-science-pack", order = "c-a", prerequisites = { nil, "electronics", "logistics-0" }, type = "technology", unit = { count = 75, ingredients = { { "automation-science-pack", 1 } }, time = 5 } }
And as it it trying to index into tech.prerequisites via tech.prerequisites[pk], that returns a nil, which obviously is another mods fault, but could be fixed here via checking for and ignoring nil's, which should probably be done as the engine itself accepts nil's as a value anyway.

So this is both an Angel's bug, it not handling values accepted by the engine itself, and a bug in this mod, leaving a nil in an array with valid values after the nil (which is a no-no in Lua, easiest fix is just to replace the value you want to erase in the prerequisites array is to just replace that value with the last value then delete the key index of the last value, or shift them all up one, which there might be a call to do that).

- 4 months ago

The definition of util.tech_remove_prerequisites does appear to be this in this mod:

function util.tech_remove_prerequisites (prototype_name, prerequisites)
  local prototype = data.raw.technology[prototype_name]
  if not prototype then return end
  for _, new_prerequisite in pairs(prerequisites) do
    for _, old_prerequisite in pairs(prototype.prerequisites) do
      if old_prerequisite == new_prerequisite then
        prototype.prerequisites[_] = nil
      end
    end
  end
end

Which is setting it to nil, which in Lua does not remove the array entry and is leaving it as nil, the proper method would be to replace the prototype.prerequisites[_] = nil line with:

        table.remove(prototype.prerequisites, _)

Do note, that will shift the array indices, so if you want to check the rest of the array then you will skip the new element in that location, so you probably want to change around the rest of the loop to iterate from the last entry to the first, as right now it is iterating from the first to the last, which will check the entries with the wrong key and you can end up removing an alternative one, so I would replace that whole function with (untested code, typed up in post, but it should be close enough if not exact):

function util.tech_remove_prerequisites (prototype_name, prerequisites)
  local prototype = data.raw.technology[prototype_name]
  if not prototype then return end
  for _, new_prerequisite in pairs(prerequisites) do
    for i = #prototype.prerequisites, 1, -1 do
      if prototype.prerequisites[i] == new_prerequisite then
        table.remove(prototype.prerequisites, i)
      end
    end
  end
end
- 4 months ago

Actually I went ahead and tested that above replacement, that fixed the issue (woo gotta love typing code in a post and getting it correct on the first try), so that should be all you need. :-)

- 4 months ago

Would you mind posting a fixed tarball?

- 4 months ago

Thanks, updated.

- 4 months ago

Awesome thanks, I'll update the server this evening then. Loving the mod!!