Page 1 of 1

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

Posted: Fri Jun 08, 2018 9:01 pm
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:

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

Posted: Fri Jun 08, 2018 9:54 pm
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

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

Posted: Fri Jun 08, 2018 9:56 pm
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.

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

Posted: Fri Jun 08, 2018 10:20 pm
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. :)

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

Posted: Sat Jun 09, 2018 12:49 am
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

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

Posted: Mon Jun 11, 2018 8:36 am
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.

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

Posted: Wed Jun 13, 2018 1:46 pm
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

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

Posted: Wed Jun 13, 2018 4:13 pm
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?