How to add-on for mod

Place to get help with not working mods / modding interface.
Post Reply
apriori
Filter Inserter
Filter Inserter
Posts: 259
Joined: Thu Feb 18, 2016 8:13 pm
Contact:

How to add-on for mod

Post 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?
Any code or mods posted by me are WTFPL, unless otherwise copyrights are specified.

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2903
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: How to add-on for mod

Post 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

apriori
Filter Inserter
Filter Inserter
Posts: 259
Joined: Thu Feb 18, 2016 8:13 pm
Contact:

Re: How to add-on for mod

Post 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?
Any code or mods posted by me are WTFPL, unless otherwise copyrights are specified.

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2903
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: How to add-on for mod

Post by darkfrei »

Every mod have separated global table. So, you are need set one of them as base mod, all another are optional.

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2903
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: How to add-on for mod

Post by darkfrei »

:shock: :idea: You can create new surface and place on it HEX- named entities, this surface can be read by another mod.

Choumiko
Smart Inserter
Smart Inserter
Posts: 1352
Joined: Fri Mar 21, 2014 10:51 pm
Contact:

Re: How to add-on for mod

Post 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

Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

Re: How to add-on for mod

Post 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

apriori
Filter Inserter
Filter Inserter
Posts: 259
Joined: Thu Feb 18, 2016 8:13 pm
Contact:

Re: How to add-on for mod

Post by apriori »

Nexela and Choumiko, that's exactly what I wanted! Thanks.
Any code or mods posted by me are WTFPL, unless otherwise copyrights are specified.

Post Reply

Return to “Modding help”