Moshine

by snouz

Hot planet to develop AI, 26 technologies, 2 new minerals, 5 buildings, many items, custom terrain, music, unique challenges...

Content
4 days ago
2.0
23.3K
Factorio: Space Age Icon Space Age Mod
Planets Logistics Trains Environment Mining Fluids Manufacturing Power

b [Fixed] Crash with Research Multipliers mod

4 months ago

Error loading mods

Failed to load mods: research-multipliers/data-final-fixes.lua:141: bad argument #1 of 2 to 'pairs' (table expected, got nil)
stack traceback:
[C]: in function 'pairs'
research-multipliers/data-final-fixes.lua:141: in function 'is_interplanetary_research'
research-multipliers/data-final-fixes.lua:184: in main chunk

Mods to be disabled:

research-multipliers (0.1.0)
☐ Reset mod settings

[Disable listed mods] [Disable all mods] [Manage mods] [Restart] [Exit]

the mod allows me to set research cost for researched manually, i wanted it to have an easy early game but it goes to high cost later. I assume the issue is probably with your science pack.

disabling moshine fixed it so this is def the issue.

A person on discord mentioned 'I smell a mistake with checking for science packs not accounting for trigger techs'

4 months ago

Hi, I read the faulty code there and

A person on discord mentioned 'I smell a mistake with checking for science packs not accounting for trigger techs'

That's exactly it.

function is_interplanetary_research(name)
for _, ingredient in pairs(data.raw.technology[name].unit.ingredients) do
if interplanetary_science_packs[ingredient[1]] then
return true;
end
end
return false;
end

The code assumes that a research has ingredients, but it's not the case always.
The correct code should ALWAYS check if something exists before accessing what's inside. So it should be:

function is_interplanetary_research(name)
if data.raw.technology[name].unit and data.raw.technology[name].unit.ingredients then
for _, ingredient in pairs(data.raw.technology[name].unit.ingredients) do
if interplanetary_science_packs[ingredient[1]] then
return true;
end
end
end
return false;
end

I haven't read the rest of the code, so I don't know why it doesn't trip on other trigger techs, but I can't really do anything on my side, you need to contact that modder, and you can give them the link to this

4 months ago

Thanks!

4 months ago

Hello, I'm the developer of research-multipliers. I hacked this mod together in a single night, so I never meant for it to be bulletproof, and more or less, my mod is at fault for crashing hard and not just ignoring technologies it fails to handle. That said, my mod works perfectly fine when it encounters other mods that adhere to the Lua API correctly.

In the main body of my mod, I properly checked whether or not the research_trigger property is set (in the case of trigger techs), and I ignore any technology that has that. This is all that should be required.

A person on discord mentioned 'I smell a mistake with checking for science packs not accounting for trigger techs'

That's exactly it.

My code was not tripping on trigger techs, it was tripping on a normal unit count technology, specifically, it was tripping on these, from Moshine: github.com/snouz/Moshine/data-final-fixes.lua#L28-L36

I checked your data.lua definitions (which calls technology.lua), and each of these technologies doesn't properly define a valid research_trigger or unit before returning (example). Technically, you're returning invalid types as a Factorio mod. This is well documented in the Lua API provided by Factorio.

More specifically, your initial data.lua implementation provides TechnologyPrototypes that have the unit as non-nil, but do not provide the time or ingredients properties, which are NOT documented as "Optional". This is why my mod crashed.

Of course, this is later corrected in data-final-fixes.lua, and it seems like it's a choice made to handle discrepancies with other mods that may modify your mod's technologies. If my mod loaded later (something I am not sure that I can control at all), my mod would not have crashed in that case either, as data-final-fixes.lua would have applied, bringing your mod within spec properly.

I'll be releasing a fix (which is just to check whether or not the technology it encounters correctly adheres to the TechnologyPrototype/TechnologyUnit types. I'll also be adjusting things to error quietly, as that should have been the default behavior anyways. I might look into options to prevent modification of ingredient counts of 1, as that generally hints at a more special research being involved.

but I can't really do anything on my side

This is inaccurate. I can only recommend that you update your technology.lua file to include valid TechnologyUnit objects so that mods running in between the data and data-final-fixes stages won't blow up when encountering your data, like mine did.

4 months ago

Ah! I didn't think of that, I had forgotten that I had set empty units to set them in final-fixes (like you said, it was to fix problems with mods adding science packs to all technology of n type, but my lab is completely separated)

I'll fix that on my side too then, thanks for looking at it.

4 months ago

Glad to hear it!

New response