[Resolved] How to "disable" control.lua...?

Place to get help with not working mods / modding interface.
User avatar
kirazy
Filter Inserter
Filter Inserter
Posts: 431
Joined: Tue Mar 06, 2018 12:18 am
Contact:

[Resolved] How to "disable" control.lua...?

Post by kirazy »

I maintain a loader mod, and I'm experimenting and testing the interactions when LoaderRedux is present.

Currently the interactions are favorable, nothing is wonky, except that the control logics from both mods are conflicting. (Specifically, LoaderRedux mod settings are ignored, and I want them to be supported.)

A solution I had thought to do is, when my mod and LoaderRedux are both activated, to defer to the control.lua in LoaderRedux.

I haven't the faintest idea how to do this, assuming this is even possible. There may be a better way to do this, but rewriting control logic is not something I know how to do.

Help? D:
Last edited by kirazy on Fri Jun 08, 2018 10:50 pm, edited 1 time in total.
User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5412
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: How to "disable" control.lua if a different mod is present?

Post by Klonan »

So you can check if the mod is active using:
http://lua-api.factorio.com/latest/LuaG ... ctive_mods

And then in your event calls, just return if the other mod is present:

Code: Select all

script.on_event(defines.events, function(event)
  if game.active_mods["OtherLoaderMod"] then return end
  on_event(event) --etc.
end
orzelek
Smart Inserter
Smart Inserter
Posts: 3928
Joined: Fri Apr 03, 2015 10:20 am
Contact:

Re: How to "disable" control.lua if a different mod is present?

Post by orzelek »

You can check for presence of other mods like this:

Code: Select all

	if game.active_mods["pyfusionenergy"] then
		--code here
	end
You need to use the mod name from json file and you can decide which parts of code to cut if it's present.
User avatar
kirazy
Filter Inserter
Filter Inserter
Posts: 431
Joined: Tue Mar 06, 2018 12:18 am
Contact:

Re: How to "disable" control.lua if a different mod is present?

Post by kirazy »

Klonan wrote:So you can check if the mod is active using:
http://lua-api.factorio.com/latest/LuaG ... ctive_mods

And then in your event calls, just return if the other mod is present:

Code: Select all

script.on_event(defines.events, function(event)
  if game.active_mods["OtherLoaderMod"] then return end
  on_event(event) --etc.
end
This worked, thank you very much. :)
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5211
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: How to "disable" control.lua if a different mod is present?

Post by eradicator »

Klonan wrote:And then in your event calls, just return if the other mod is present:

Code: Select all

script.on_event(defines.events, function(event)
  if game.active_mods["OtherLoaderMod"] then return end
  on_event(event) --etc.
end
Wouldn't it be more prudent to not define the event in the first place?

Code: Select all

local skip = game.active_mods["OtherLoaderMod"] and true or false
if not skip then script.on_event(defines.events.on_stuff_happend,function(event)
 --do more stuff
 end) end
User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: [Resolved] How to "disable" control.lua...?

Post by bobingabout »

IF you know what his settings are (and you're probably going to want to do this any way in case he changes them), you can just check to see if the setting exists.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.
User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5412
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: How to "disable" control.lua if a different mod is present?

Post by Klonan »

eradicator wrote:
Klonan wrote:And then in your event calls, just return if the other mod is present:

Code: Select all

script.on_event(defines.events, function(event)
  if game.active_mods["OtherLoaderMod"] then return end
  on_event(event) --etc.
end
Wouldn't it be more prudent to not define the event in the first place?

Code: Select all

local skip = game.active_mods["OtherLoaderMod"] and true or false
if not skip then script.on_event(defines.events.on_stuff_happend,function(event)
 --do more stuff
 end) end
'game' namespace isn't available when the script is loading, so you would have to conditionally register the event within the on_load, which is more hassle and risk
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5211
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: How to "disable" control.lua if a different mod is present?

Post by eradicator »

Klonan wrote:
eradicator wrote:
Klonan wrote:And then in your event calls, just return if the other mod is present:

Code: Select all

script.on_event(defines.events, function(event)
  if game.active_mods["OtherLoaderMod"] then return end
  on_event(event) --etc.
end
Wouldn't it be more prudent to not define the event in the first place?

Code: Select all

local skip = game.active_mods["OtherLoaderMod"] and true or false
if not skip then script.on_event(defines.events.on_stuff_happend,function(event)
 --do more stuff
 end) end
'game' namespace isn't available when the script is loading, so you would have to conditionally register the event within the on_load, which is more hassle and risk
Hm...true. Why is that table in game then though, it can't change at that point can it?
Post Reply

Return to “Modding help”