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?
How to add-on for mod
Re: How to add-on for mod
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
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
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
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
Take a look at http://lua-api.factorio.com/latest/LuaRemote.htmlapriori 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?
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
You want http://lua-api.factorio.com/0.15.2/LuaRemote.html
And Choumiko beat me too it
Mod B
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,
}
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
Nexela and Choumiko, that's exactly what I wanted! Thanks.