Page 1 of 1
remote interface call questions
Posted: Fri Apr 29, 2016 1:01 pm
by Galacticruler
I was wondering if it was possible to do a few things using the
Code: Select all
remote.add_interface(interface_name, table_of_functions)
code. Namely make it see if two mods are installed and only fire-up if both are there, and secondly adding an entire turret only in the event that one of them is installed.
Re: remote interface call questions
Posted: Fri Apr 29, 2016 1:13 pm
by Choumiko
If both mods have a remote interface it will work:
Code: Select all
if remote.interfaces.modA and remote.interfaces.modB then
but since you're talking about adding a turret i think you want this to happen in data.lua? data.lua doesn't have remote available, so you'll have to check data.raw for items/turrets added by these 2 mods. And add them as optional depenencies, so they are loaded before your mod (or do it in data-updates.lua)
Code: Select all
if data.raw["item"]["item-from-modA"] and data.raw["item"]["item-from-modB"] then
Re: remote interface call questions
Posted: Fri Apr 29, 2016 1:26 pm
by Galacticruler
Choumiko wrote:If both mods have a remote interface it will work:
Code: Select all
if remote.interfaces.modA and remote.interfaces.modB then
but since you're talking about adding a turret i think you want this to happen in data.lua? data.lua doesn't have remote available, so you'll have to check data.raw for items/turrets added by these 2 mods. And add them as optional depenencies, so they are loaded before your mod (or do it in data-updates.lua)
Code: Select all
if data.raw["item"]["item-from-modA"] and data.raw["item"]["item-from-modB"] then
after the then on the data.raw what would I do to create the entity, item, and recipe for the new turret? as well as add it to a technology?
Re: remote interface call questions
Posted: Fri Apr 29, 2016 1:31 pm
by prg
The usual data:extend() thing.
Re: remote interface call questions
Posted: Sun May 01, 2016 7:23 pm
by Galacticruler
Choumiko wrote:
Code: Select all
if data.raw["item"]["item-from-modA"] and data.raw["item"]["item-from-modB"] then
okay, so I'm probably doing this wrong, but it keeps saying the item I'm trying to index is a nil value.
currently it looks like this:
Code: Select all
if data.raw["charge-pack"]["advanced-weaponry"] then
Re: remote interface call questions
Posted: Sun May 01, 2016 7:32 pm
by prg
"charge-pack" is not a valid type defined by the game. You can't just put something you made up yourself there. What is the prototype you're trying to access?
Re: remote interface call questions
Posted: Sun May 01, 2016 7:53 pm
by Galacticruler
prg wrote:"charge-pack" is not a valid type defined by the game. You can't just put something you made up yourself there. What is the prototype you're trying to access?
Oh, that makes a bit more sense, its not an item name it the item type?
Re: remote interface call questions
Posted: Sun May 01, 2016 8:09 pm
by prg
It's data.raw["type"]["name"], so e.g. data.raw["item"]["small-electric-pole"] for the item in your inventory or data.raw["electric-pole"]["small-electric-pole"] for the placed entity. Just use the type and name of the prototype.