Page 1 of 1

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

Posted: Thu Feb 06, 2020 4:31 pm
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 3500 times
error.png
error.png (27.7 KiB) Viewed 3500 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")

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

Posted: Thu Feb 06, 2020 11:36 pm
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."

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

Posted: Fri Feb 07, 2020 12:34 am
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).

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

Posted: Fri Feb 07, 2020 2:17 am
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 :)

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

Posted: Fri Feb 07, 2020 2:35 am
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.

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

Posted: Fri Feb 07, 2020 3:15 am
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

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

Posted: Fri Feb 07, 2020 4:05 am
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.

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

Posted: Fri Feb 07, 2020 9:11 pm
by Rseding91
Thanks for the report and for the save file + mod to reproduce the issue. It's now fixed for the next release.

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

Posted: Sat Feb 08, 2020 12:53 pm
by jan1i3
Thank you for fixing it :D