Page 1 of 1

How to add-on for mod

Posted: Tue Apr 25, 2017 9:43 pm
by apriori
I want to make an add-on for my mod. The original mod adds buildable entity. It's being "remembered" in a list when built. My add-on is gonna add a ticker for these entities. How to realize it more optimal? I've got only one way in my mind:
Get the list of entities from the original mod and then "tick" through this list. How to do it? I mean how to make some API in my original mod to let another mods request something?

EDIT: Which data types can be used in such interaction between mods?

Re: How to add-on for mod

Posted: Wed Apr 26, 2017 7:23 am
by darkfrei
I have used it here viewtopic.php?f=135&t=44345

Code: Select all

--  init 
function initEntity (entity)
   if not entity then return end
   if not global.entities then global.entities = {} end
   if not global.ID then global.ID = 1 else global.ID = global.ID + 1 end
   printAll("101 ".. entity.name .. " start init: " .. #global.entities)
   local taCo = tableContains(global.entities, entity)
   if taCo then return end
   local NewEntity = {
      name = entity.name,
      position = entity.position,
      pShift = {x=0, y=0},
      entity = entity,
      ID = global.ID
      }
   global.entities[global.ID] = NewEntity
   -- table.insert(global.entities, NewEntity)
   printAll("102 ".. entity.name .. " end init: " .. #global.entities)
end

Re: How to add-on for mod

Posted: Wed Apr 26, 2017 10:03 am
by apriori
darkfrei wrote:I have used it here viewtopic.php?f=135&t=44345
code
Nah, it's not what I want... I want my mod to "ask" another mod to give me some information. So, another mod should be possible to "hear" my request and to "answer" it. How to do it?

Re: How to add-on for mod

Posted: Wed Apr 26, 2017 10:25 am
by darkfrei
Every mod have separated global table. So, you are need set one of them as base mod, all another are optional.

Re: How to add-on for mod

Posted: Wed Apr 26, 2017 10:29 am
by darkfrei
:shock: :idea: You can create new surface and place on it HEX- named entities, this surface can be read by another mod.

Re: How to add-on for mod

Posted: Wed Apr 26, 2017 10:46 am
by Choumiko
apriori wrote:Nah, it's not what I want... I want my mod to "ask" another mod to give me some information. So, another mod should be possible to "hear" my request and to "answer" it. How to do it?
Take a look at http://lua-api.factorio.com/latest/LuaRemote.html

Usage examples:
https://github.com/Choumiko/RailTanker/ ... l.lua#L413

https://github.com/Choumiko/SmartTrains ... n.lua#L581

SmartTrains asks Railtanker about liquid stored in a Railtanker

Re: How to add-on for mod

Posted: Wed Apr 26, 2017 10:51 am
by Nexela
You want http://lua-api.factorio.com/0.15.2/LuaRemote.html

And Choumiko beat me too it

Code: Select all

local function myfunction(first, second)
  game.print("Just like the hello, first and second will the the third and fourth arguments in the call)
end

remote.add_interface("name-of-interface", {
  hello = function(message) game.print(message or "Hello") end,
  me = true,
  this = myfunction,
}
Mod B

Code: Select all

if remote.interfaces["name-of-interface"] then 
  remote.call("name-of-interface", "hello", "It will print this")
end

Re: How to add-on for mod

Posted: Wed Apr 26, 2017 3:50 pm
by apriori
Nexela and Choumiko, that's exactly what I wanted! Thanks.