Code: Select all
BaseClass = {}
BaseClass.__index = BaseClass
setmetatable(BaseClass, {
__call = function (cls, ...)
local self = setmetatable({}, cls)
self:_init(...)
return self
end,
})
function BaseClass:_init(name)
self.name = name
end
function BaseClass:set_name(name)
self.name = name
end
function BaseClass:get_name()
return self.name
end
Code: Select all
Product = {}
Product.__index = Product
setmetatable(Product, {
__index = BaseClass,
__call = function (cls, ...)
local self = setmetatable({}, cls)
self:_init(...)
return self
end,
})
function Product:_init(name, amount)
BaseClass._init(self, name)
self.amount = amount_produced
end
Now this works great when you start your game, as I require those classes in my control.lua file. When saving and loading though, they are not there anymore. Now this makes sense, as global lua variables are not persisted when saving, only values in the factorio global table are. But I have trouble getting them to 'reload' when you load the save. Now I know that they should probably be reloaded in the on_load() listener, but, after some research and testing, I haven't gotten it to work. I'm sure it is not hard, but I can't work it out. Anyone got a solution?