[0.18.4] script.active_mods contains mods during mod initialization which have been disabled when loading a save

This subforum contains all the issues which we already resolved.
User avatar
jan1i3
Long Handed Inserter
Long Handed Inserter
Posts: 59
Joined: Sun Dec 09, 2018 1:36 pm
Contact:

[0.18.4] script.active_mods contains mods during mod initialization which have been disabled when loading a save

Post by jan1i3 »

TL;DR
When loading a save which had a mod enabled, which is now disabled, it will still be in script.active_mods during mod initialization.
Expected
script.active_mods should always only have mods in it which are currently active.
Example
save_info.png
save_info.png (43.84 KiB) Viewed 4052 times
error.png
error.png (27.7 KiB) Viewed 4052 times
ScriptActiveModsIssue/control.lua:

Code: Select all

if script.active_mods["ScriptActiveModsIssueDummy"] then
  require("__ScriptActiveModsIssueDummy__/empty.lua") -- this is line 3
end
Reproduce
  1. Only have the mod ScriptActiveModsIssue enabled
  2. Load the provided save
Or, for full reproduction:
  1. Have both provided mods enabled
  2. Create a new world
  3. Save it
  4. Disable the mod ScriptActiveModsIssueDummy
  5. Load the previously saved game
Workaround
keep using pcall require, which script.active_mods was supposed to replace ;)

Code: Select all

pcall(require, "__ScriptActiveModsIssueDummy__/empty.lua")
Attachments
ScriptActiveModsIssueSave.zip
(1.13 MiB) Downloaded 124 times
ScriptActiveModsIssueDummy_0.0.1.zip
(502 Bytes) Downloaded 132 times
ScriptActiveModsIssue_0.0.1.zip
(567 Bytes) Downloaded 137 times
factorio-current.log
(14.88 KiB) Downloaded 137 times
Also known as JanSharp. jan1i3 was/is my old name ;)
Honktown
Smart Inserter
Smart Inserter
Posts: 1041
Joined: Thu Oct 03, 2019 7:10 am
Contact:

Re: [0.18.4] script.active_mods contains mods during mod initialization which have been disabled when loading a save

Post by Honktown »

Bug doesn't occur in 0.17.79.

A side note, is that for a new game [in 17.79], script.active_mods doesn't exist, so I had to do an if pcall() and... to get it to go.

Edit wait, this is strange. The pcall returns true when I do
Nevermind I get false. Even when loading a normal game there is no script.active_mods, it only exists while the game is running and in the game table

Code: Select all

pcall(function() return script.active_mods end)
but then if I remove the pcall I get

Code: Select all

"Error AppManagerStates.cpp:1443: LuaBootstrap doesn't contain key active_mods."
I have mods! I guess!
Link
Honktown
Smart Inserter
Smart Inserter
Posts: 1041
Joined: Thu Oct 03, 2019 7:10 am
Contact:

Re: [0.18.4] script.active_mods contains mods during mod initialization which have been disabled when loading a save

Post by Honktown »

Related topics:

see the last post:
viewtopic.php?t=52040

https://stackoverflow.com/questions/444 ... ies-in-lua

https://github.com/mexmer/ScienceCostTweakerM/issues/28
Instead they state that all require calls should be top level so they are always require'd regardless, and instead conditional tests should be put into the file itself or the calls to things inside the files.
The interpreter probably hits the require and ignores that it's in a conditional. Other people have seemed to have issues with conditional requires (probably because of run-time issues like if a library was required by the time a function is called, which would mess up things which pre-compile/interpret syntax).
I have mods! I guess!
Link
User avatar
jan1i3
Long Handed Inserter
Long Handed Inserter
Posts: 59
Joined: Sun Dec 09, 2018 1:36 pm
Contact:

Re: [0.18.4] script.active_mods contains mods during mod initialization which have been disabled when loading a save

Post by jan1i3 »

I don't exactly see how what you've said/posted is related.

The issue is specific to script.active_mods.

Before 0.18 to do conditional requires in the control stage you had to pcall require.
With 0.18 came script.active_mods with the purpose of no longer needing pcall, and having the version numbers available during mod initialization.
(As I hinted at in the Workaround section)
Note that this was an issue since the very start, I just didn't report it until now.

I feel like you misunderstood, which is fine :)
Also known as JanSharp. jan1i3 was/is my old name ;)
Honktown
Smart Inserter
Smart Inserter
Posts: 1041
Joined: Thu Oct 03, 2019 7:10 am
Contact:

Re: [0.18.4] script.active_mods contains mods during mod initialization which have been disabled when loading a save

Post by Honktown »

jan1i3 wrote: Fri Feb 07, 2020 2:17 am I don't exactly see how what you've said/posted is related.

The issue is specific to script.active_mods.

Before 0.18 to do conditional requires in the control stage you had to pcall require.
With 0.18 came script.active_mods with the purpose of no longer needing pcall, and having the version numbers available during mod initialization.
(As I hinted at in the Workaround section)
Note that this was an issue since the very start, I just didn't report it until now.

I feel like you misunderstood, which is fine :)
I wanted to see if I could reproduce it, and I'm on 0.17.79. script.active_mods doesn't even exist, unless I'm doing something so stupidly obvious I'm missing it. Although it's under https://lua-api.factorio.com/latest/LuaBootstrap.html , it only exists in "game"

P.s. if Factorio features conditional requires that's unique. It looks like other implementations have issues with it.
I have mods! I guess!
Link
User avatar
jan1i3
Long Handed Inserter
Long Handed Inserter
Posts: 59
Joined: Sun Dec 09, 2018 1:36 pm
Contact:

Re: [0.18.4] script.active_mods contains mods during mod initialization which have been disabled when loading a save

Post by jan1i3 »

Oh I see - yea if you want to reproduce it, you'll have to be in 0.18
The "latest" api is 0.18.4 (currently), so script.active_mods is there
see the 0.17.79 api where it isn't
Also known as JanSharp. jan1i3 was/is my old name ;)
Honktown
Smart Inserter
Smart Inserter
Posts: 1041
Joined: Thu Oct 03, 2019 7:10 am
Contact:

Re: [0.18.4] script.active_mods contains mods during mod initialization which have been disabled when loading a save

Post by Honktown »

jan1i3 wrote: Fri Feb 07, 2020 3:15 am Oh I see - yea if you want to reproduce it, you'll have to be in 0.18
The "latest" api is 0.18.4 (currently), so script.active_mods is there
see the 0.17.79 api where it isn't
Ah, thank you. I assumed "latest" was the latest stable.
I have mods! I guess!
Link
Rseding91
Factorio Staff
Factorio Staff
Posts: 14250
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [0.18.4] script.active_mods contains mods during mod initialization which have been disabled when loading a save

Post by Rseding91 »

Thanks for the report and for the save file + mod to reproduce the issue. It's now fixed for the next release.
If you want to get ahold of me I'm almost always on Discord.
User avatar
jan1i3
Long Handed Inserter
Long Handed Inserter
Posts: 59
Joined: Sun Dec 09, 2018 1:36 pm
Contact:

Re: [0.18.4] script.active_mods contains mods during mod initialization which have been disabled when loading a save

Post by jan1i3 »

Thank you for fixing it :D
Also known as JanSharp. jan1i3 was/is my old name ;)
Post Reply

Return to “Resolved Problems and Bugs”