Sure: here is a simple a example. Added --snap-- comment to where I cut the code, but the general idea is like this:
framework.lua
Code: Select all
framework.data = [[
registry = {}
function set(entity,key,value)
if not data.registry[entity.id] then data.addEntity(entity) end
data.registry[entity.id][key] = value
end
function removeEntity(entity)
data.registry[entity.id] = nil
end
-- snap --
]]
-- snap --
-- this door loads script entities
cloneObject{
name = "LoGFramework",
baseObject = "dungeon_door_metal",
onOpen = function()
-- load framework sources to script entities
spawn("script_entity", 1,1,1,0,'data')
-- snap --
fw:setSource(framework.data)
-- load modules
for moduleName,source in pairs(modules) do
if (logfw_init.options.modules[moduleName]) then
spawn("script_entity", 1,1,1,0,moduleName)
script = findEntity(moduleName)
script:setSource(source)
end
end
end,
}
create script entity named logfw_init in your dungeon
and put this code to it:
Code: Select all
options = {}
-- enable some modules
options.modules = {
monsters_can_open_doors = false,
damage_dealing_doors = true,
illusion_walls = true,
}
spawn("LoGFramework", 1,1,1,0,'fwInit')
fwInit:open() -- this loads all script entities defined in framework.lua
fwInit:destroy()
If I put all code to single script-entity it would be a mess and pretty difficult to maintain in ingame editor, I have now about 500 lines of code in framwork.lua. And I like that I am able to develop new features in editor and then just copy-paste it to framework.lua when it's done, and it isn't showing in editor anymore. And if framework.lua grows too big, I can make another lua-file which adds script_entities to modules-table and include it to framwork.lua.