[Done] Detect other mods installed

Place to get help with not working mods / modding interface.
Post Reply
TheSAguy
Smart Inserter
Smart Inserter
Posts: 1449
Joined: Mon Jan 13, 2014 6:17 pm
Contact:

[Done] Detect other mods installed

Post 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.
Last edited by TheSAguy on Fri May 11, 2018 8:18 pm, edited 3 times in total.

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2903
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Detect other mods installed

Post by darkfrei »

I think it's possible only with reading some items/ entities, if it exists then installed.

Exasperation
Long Handed Inserter
Long Handed Inserter
Posts: 88
Joined: Fri Apr 22, 2016 9:55 pm
Contact:

Re: Detect other mods installed

Post 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,

Code: Select all

if mods[modname] then
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

Code: Select all

if game.active_mods[modname] then
will do it.

TheSAguy
Smart Inserter
Smart Inserter
Posts: 1449
Joined: Mon Jan 13, 2014 6:17 pm
Contact:

Re: Detect other mods installed

Post by TheSAguy »

Exasperation wrote: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,

Code: Select all

if mods[modname] then
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

Code: Select all

if game.active_mods[modname] then
will do it.
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.
Attachments
control.lua
(34.49 KiB) Downloaded 114 times

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2903
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Detect other mods installed

Post 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

Bilka
Factorio Staff
Factorio Staff
Posts: 3123
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: Detect other mods installed

Post by Bilka »

And it won't print anyways in on_init if you are creating a new world.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.

TheSAguy
Smart Inserter
Smart Inserter
Posts: 1449
Joined: Mon Jan 13, 2014 6:17 pm
Contact:

Re: Detect other mods installed

Post 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")

Bilka
Factorio Staff
Factorio Staff
Posts: 3123
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: Detect other mods installed

Post 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
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.

TheSAguy
Smart Inserter
Smart Inserter
Posts: 1449
Joined: Mon Jan 13, 2014 6:17 pm
Contact:

Re: Detect other mods installed

Post by TheSAguy »

I placed my code in both On-Init and on-Change, but I'm not getting any message displayed.

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2903
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Detect other mods installed

Post 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")

TheSAguy
Smart Inserter
Smart Inserter
Posts: 1449
Joined: Mon Jan 13, 2014 6:17 pm
Contact:

Re: Detect other mods installed

Post by TheSAguy »

UGH, I knew it was user error, I just could not find it!
Thanks.

TheRedBull
Manual Inserter
Manual Inserter
Posts: 3
Joined: Fri Sep 15, 2017 10:16 pm
Contact:

Re: [Resolved] Detect other mods installed

Post by TheRedBull »

I'd been trying to figure this out for the last couple days... thanks for this thread!

TheSAguy
Smart Inserter
Smart Inserter
Posts: 1449
Joined: Mon Jan 13, 2014 6:17 pm
Contact:

Re: Detect other mods installed

Post 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:

Code: Select all

game.active_mods["mod name"] then
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.

orzelek
Smart Inserter
Smart Inserter
Posts: 3911
Joined: Fri Apr 03, 2015 10:20 am
Contact:

Re: Detect other mods installed

Post 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?

lukavminaev
Manual Inserter
Manual Inserter
Posts: 1
Joined: Wed Jul 31, 2019 8:04 am
Contact:

Re: Detect other mods installed

Post by lukavminaev »

Exasperation wrote:
Mon Aug 21, 2017 5:57 am

In the control stage, you have access to http://lua-api.factorio.com/latest/LuaG ... ctive_mods instead, so

Code: Select all

if game.active_mods[modname] then
will do it.
Its late but the correct code is

Code: Select all

if type(game.active_mods["modname"]) then

Rseding91
Factorio Staff
Factorio Staff
Posts: 13175
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Detect other mods installed

Post 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.
If you want to get ahold of me I'm almost always on Discord.

Post Reply

Return to “Modding help”