Page 1 of 1
[Done] Detect other mods installed
Posted: Mon Aug 21, 2017 4:37 am
by TheSAguy
What is the best/correct way to detect if another mod is also being used?
For both Control.lua and Data.lua please.
Thanks.
Re: Detect other mods installed
Posted: Mon Aug 21, 2017 4:44 am
by darkfrei
I think it's possible only with reading some items/ entities, if it exists then installed.
Re: Detect other mods installed
Posted: Mon Aug 21, 2017 5:57 am
by Exasperation
It's actually pretty easy. From
http://lua-api.factorio.com/latest/Data-Lifecycle.html:
The settings stage wrote:a global table mods exists that contains a mapping of mod name to mod version for all enabled mods
The data stage wrote:The global table mods still exists
So, in the data stage,
will tell you if a mod named modname exists.
In the control stage, you have access to
http://lua-api.factorio.com/latest/LuaG ... ctive_mods instead, so
will do it.
Re: Detect other mods installed
Posted: Tue Aug 22, 2017 4:02 pm
by TheSAguy
The control stage does not seem to work for me.
I tried the following two:
Code: Select all
if game.active_mods[EndgameCombat] then
game.surfaces[1].print("You have Endgame Combat Installed, not compatable with Natural Evolution Buildings")
end
and
Code: Select all
for name, version in pairs(game.active_mods) do
game.surfaces[1].print(name .. " version " .. version)
end
I tried them in "script.on_init", "script.on_configuration_changed" and "script.on_load". Crashes in On_load and does not seem the have any effect in the other two.
Anyone see what I'm doing wrong here?
Control attached.
Thanks.
Re: Detect other mods installed
Posted: Tue Aug 22, 2017 4:06 pm
by darkfrei
TheSAguy wrote:
Code: Select all
if game.active_mods[EndgameCombat] then
game.surfaces[1].print("You have Endgame Combat Installed, not compatable with Natural Evolution Buildings")
end
EndgameCombat is link, "EndgameCombat" is word
Code: Select all
if game.active_mods["EndgameCombat"] then
game.surfaces[1].print("You have Endgame Combat Installed, not compatable with Natural Evolution Buildings")
end
Re: Detect other mods installed
Posted: Tue Aug 22, 2017 5:17 pm
by Bilka
And it won't print anyways in on_init if you are creating a new world.
Re: Detect other mods installed
Posted: Tue Aug 22, 2017 5:28 pm
by TheSAguy
I'm not sure what's going on here, I'm can't seem to even display a message without any condition.
The below by itself is not displaying me anything...
Code: Select all
game.surfaces[1].print("You have Endgame Combat Installed, not compatible with Natural Evolution Buildings")
Re: Detect other mods installed
Posted: Tue Aug 22, 2017 5:32 pm
by Bilka
TheSAguy wrote:I'm not sure what's going on here, I'm can't seem to even display a message without any condition.
The below by itself is not displaying me anything...
Code: Select all
game.surfaces[1].print("You have Endgame Combat Installed, not compatible with Natural Evolution Buildings")
Are you creating a new world with the mod? Then print won't work in on_init because it happens before players are created. Source: Nexela
Re: Detect other mods installed
Posted: Tue Aug 22, 2017 5:38 pm
by TheSAguy
I placed my code in both On-Init and on-Change, but I'm not getting any message displayed.
Re: Detect other mods installed
Posted: Tue Aug 22, 2017 5:49 pm
by darkfrei
TheSAguy wrote:I'm not sure what's going on here, I'm can't seem to even display a message without any condition.
The below by itself is not displaying me anything...
Code: Select all
game.surfaces[1].print("You have Endgame Combat Installed, not compatible with Natural Evolution Buildings")
Players, not surfaces:
Code: Select all
/c game.players[1].print("You have Endgame Combat Installed, not compatible with Natural Evolution Buildings")
Re: Detect other mods installed
Posted: Tue Aug 22, 2017 5:58 pm
by TheSAguy
UGH, I knew it was user error, I just could not find it!
Thanks.
Re: [Resolved] Detect other mods installed
Posted: Sat Sep 16, 2017 4:42 am
by TheRedBull
I'd been trying to figure this out for the last couple days... thanks for this thread!
Re: Detect other mods installed
Posted: Wed Jan 17, 2018 11:35 pm
by TheSAguy
How can I determine if a mod is installed during control.lua, but
not during "script.on_configuration_changed" or "script.on_init".
There I can use:
I need to determined if Alien Biomes is running, and if running it should use a different table. I cant use "game" though during normal control as in below
Code: Select all
if game.active_mods["alien-biomes"] then
terrains = require("libs/trees-and-terrains_alien_boimes")
else
terrains = require("libs/trees-and-terrains")
end
Thanks.
Re: Detect other mods installed
Posted: Wed Jan 17, 2018 11:40 pm
by orzelek
I've been using the active-mods method in control.lua without problems.
I don't think it's limited to those events - I have a use from remote interface and it seems to work.
You are trying to make conditional require statements in that if - maybe thats whats not working properly?
Re: Detect other mods installed
Posted: Mon Apr 20, 2020 12:20 am
by lukavminaev
Its late but the correct code is
Code: Select all
if type(game.active_mods["modname"]) then
Re: Detect other mods installed
Posted: Mon Apr 20, 2020 12:28 am
by Rseding91
lukavminaev wrote: Mon Apr 20, 2020 12:20 am
Its late but the correct code is
Code: Select all
if type(game.active_mods["modname"]) then
That's just extra work to get the same results. You don't need the type check.