Optional mod requirements

Place to get help with not working mods / modding interface.
User avatar
Ranakastrasz
Smart Inserter
Smart Inserter
Posts: 2173
Joined: Thu Jun 12, 2014 3:05 am
Contact:

Optional mod requirements

Post by Ranakastrasz »

I've seen mods that can require other mods, and implement things, like recipes or techs differently depending on what mods are enabled. How is this done?
My Mods:
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16
User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5267
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: Optional mod requirements

Post by Klonan »

This is done in the info.json

example

Code: Select all

{
  "name": "foo-mod",
  "version": "0.1.0",
  "title": "Foo Mod",
  "author": "Factorio team",
  "contact": "dev@factorio.com",
  "homepage": "http://factorio.com",
  "description": "Basic mod with all the default game data and standard campaign.",
  "dependencies": ["base >= 0.4.1", "scenario-pack", "? bar = 0.3"]
}
From: https://forums.factorio.com/wiki/index.ph ... nformation
User avatar
Ranakastrasz
Smart Inserter
Smart Inserter
Posts: 2173
Joined: Thu Jun 12, 2014 3:05 am
Contact:

Re: Optional mod requirements

Post by Ranakastrasz »

Ok. That covers half of it. How do I set different recipes depending on those criteria?
My Mods:
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16
orzelek
Smart Inserter
Smart Inserter
Posts: 3924
Joined: Fri Apr 03, 2015 10:20 am
Contact:

Re: Optional mod requirements

Post by orzelek »

Ranakastrasz wrote:Ok. That covers half of it. How do I set different recipes depending on those criteria?
That depends on the mod you are looking for.

I'd recommend looking at bob's mods and his config mod integration in other mods.
User avatar
Arch666Angel
Smart Inserter
Smart Inserter
Posts: 1636
Joined: Sun Oct 18, 2015 11:52 am
Contact:

Re: Optional mod requirements

Post by Arch666Angel »

It depends if you are doing several mods and want to link them, then go with what orzelek said, cause bob did a really good Job and with some longer staring his methods are really good.

Otherwise it depends, first you have to find something unique withhin the other mod you want to detect, for example an entity or item and then run a check for it. But that can be more complicated than it sounds, depending on where the entity is defined and where you want to check for it.
Supercheese
Filter Inserter
Filter Inserter
Posts: 841
Joined: Mon Sep 14, 2015 7:40 am
Contact:

Re: Optional mod requirements

Post by Supercheese »

Generally speaking, after adding the optional dependency in info.json, you'll want to run an if check to test if a certain item/entity/tech/etc. from the other mod exists, and if it does, then adjust your mod accordingly.

From my Satellite Uplink Station, a data.lua example:

Code: Select all

if data.raw["item"]["gilded-copper-cable"] and enableBobUpdates then
	data.raw["recipe"]["uplink-station"].ingredients[5] = {"insulated-cable", 100}
end
Here (although I don't remember why) I even had the test based off the existence of one item from bob's electronics but changed the recipe to use a different item. The "enableBobUpdates" is just a config.lua variable that can be manually set to true or false.

Similar tests exist for control.lua, where you don't use data.raw but rather:

Code: Select all

		if game.item_prototypes["upgrade-planner"] then
			player.insert({name="upgrade-planner", count=1})
		end
User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5267
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: Optional mod requirements

Post by Klonan »

Note that you chekc with the data.lua, but if your mod loads first, then that item might not be loaded into the data yet, and thus it works too to use a data-updates.lua, which is only loaded after all the other mods data.lua files.
Supercheese
Filter Inserter
Filter Inserter
Posts: 841
Joined: Mon Sep 14, 2015 7:40 am
Contact:

Re: Optional mod requirements

Post by Supercheese »

Klonan wrote:Note that you chekc with the data.lua, but if your mod loads first, then that item might not be loaded into the data yet, and thus it works too to use a data-updates.lua, which is only loaded after all the other mods data.lua files.
I thought that was the entire purpose of the optional dependency, to ensure that the mod you declared in info.json to look out for is loaded before yours.
User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5267
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: Optional mod requirements

Post by Klonan »

Supercheese wrote:
Klonan wrote:Note that you chekc with the data.lua, but if your mod loads first, then that item might not be loaded into the data yet, and thus it works too to use a data-updates.lua, which is only loaded after all the other mods data.lua files.
I thought that was the entire purpose of the optional dependency, to ensure that the mod you declared in info.json to look out for is loaded before yours.
Oh yea that might be right...
User avatar
Ranakastrasz
Smart Inserter
Smart Inserter
Posts: 2173
Joined: Thu Jun 12, 2014 3:05 am
Contact:

Re: Optional mod requirements

Post by Ranakastrasz »

I can't figure out how to get this data in my control file. data doesn't exist apperently. (Presumably because data.raw only exists when game is first loading)
game doesn't exist for some reason, even though It only runs when I start a game.

Any suggestions on what else I might try?
My Mods:
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16
User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3716
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: Optional mod requirements

Post by DaveMcW »

You can use game.entity_prototypes, but not in on_load.
User avatar
Ranakastrasz
Smart Inserter
Smart Inserter
Posts: 2173
Joined: Thu Jun 12, 2014 3:05 am
Contact:

Re: Optional mod requirements

Post by Ranakastrasz »

Got it to work. Thanks.

Still really awkward... Why can't you just validate mods like the dependency part?
My Mods:
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16
Post Reply

Return to “Modding help”