Code: Select all
glob.boilernames={}
remote.addinterface("F-mod", {
addboiler=function(boilername)
table.insert(glob.boilernames,boilername)
game.getplayer().print("Boiler added")
end
})
remote.call("F-mod", "addboiler", "boiler")
Code: Select all
glob.boilernames={}
remote.addinterface("F-mod", {
addboiler=function(boilername)
table.insert(glob.boilernames,boilername)
game.getplayer().print("Boiler added")
end
})
remote.call("F-mod", "addboiler", "boiler")
You can quickly test this by placing game.player.print("test") on the first line of control.lua. When you do you'll find that it runs once when the game is created and again every time you load the save (which makes sense).drs9999 wrote:[...]outside everyother event is just called once(when you start a new game)[...]
Hm, assuming that you are not building new boilers in the old saves it is possible that glob.boilernames={} is being ran when the save is loaded and deleting everything in the table (and maybe then lua's garbage collector is deleting the empty table?). Why not use glob.boilernames={} in game.oninit (also, not sure how Factorio reacts to a remote interface being called by the same script that created it)ficolas wrote:but when I use an old save, it doesnt work.
Code: Select all
game.oninit(function()
glob.boilernames = {}
for k, entity in pairs(game.entityprototypes) do --there is also an item prototypes if you needed it
if entity.type == "boiler" then
local boiler = {name=entity.name}
table.insert(glob.boilernames, boiler)
end
end
end)
game.onevent(defines.event.onentitybuilt, function()
local isboiler = false
for k, boiler in pairs(glob.boilernames) do
if event.entity.name == boiler.name then
isboiler = true
break
end
end
if isboiler then
--code to add boiler entity to tables used in checking for salt extractors (or whatever)
end
end)