Page 1 of 1
Optional mod requirements
Posted: Thu Feb 18, 2016 5:32 pm
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?
Re: Optional mod requirements
Posted: Thu Feb 18, 2016 6:27 pm
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
Re: Optional mod requirements
Posted: Thu Feb 18, 2016 6:32 pm
by Ranakastrasz
Ok. That covers half of it. How do I set different recipes depending on those criteria?
Re: Optional mod requirements
Posted: Thu Feb 18, 2016 7:53 pm
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.
Re: Optional mod requirements
Posted: Thu Feb 18, 2016 8:56 pm
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.
Re: Optional mod requirements
Posted: Thu Feb 18, 2016 9:51 pm
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
Re: Optional mod requirements
Posted: Thu Feb 18, 2016 10:25 pm
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.
Re: Optional mod requirements
Posted: Thu Feb 18, 2016 10:34 pm
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.
Re: Optional mod requirements
Posted: Thu Feb 18, 2016 10:38 pm
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...
Re: Optional mod requirements
Posted: Sun May 29, 2016 2:08 am
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?
Re: Optional mod requirements
Posted: Sun May 29, 2016 2:38 am
by DaveMcW
You can use game.entity_prototypes, but not in on_load.
Re: Optional mod requirements
Posted: Sun May 29, 2016 3:24 am
by Ranakastrasz
Got it to work. Thanks.
Still really awkward... Why can't you just validate mods like the dependency part?