diff --git a/data.lua b/data.lua index 13a793a..6f47517 100644 --- a/data.lua +++ b/data.lua @@ -8,9 +8,12 @@ function mapsync.save_data(key, value) return end - local f = assert(global_env.io.open(data_backend_def.path .. "/" .. key .. ".lua", "w")) - f:write(minetest.serialize(value)) + local filename = data_backend_def.path .. "/" .. key .. ".lua" + local f = assert(global_env.io.open(filename, "w")) + local data = minetest.serialize(value) + f:write(data) f:close() + minetest.log("action", "[mapsync] wrote " .. #data .. " bytes of data to '" .. filename .. "'") end -- load simple key-value data diff --git a/integrations/elevator.lua b/integrations/elevator.lua index fe15d0f..bf99c5d 100644 --- a/integrations/elevator.lua +++ b/integrations/elevator.lua @@ -8,8 +8,12 @@ function elevator.save_elevator() old_elevator_save_elevator() end --- load from backend if available -local data = mapsync.load_data("elevator") -if data and data.motors then - elevator.motors = data.motors -end \ No newline at end of file +local function load() + -- load from backend if available + local data = mapsync.load_data("elevator") + if data and data.motors then + elevator.motors = data.motors + end +end + +minetest.register_on_mods_loaded(load) \ No newline at end of file diff --git a/integrations/hyperloop.lua b/integrations/hyperloop.lua index 3791159..bf2438e 100644 --- a/integrations/hyperloop.lua +++ b/integrations/hyperloop.lua @@ -21,4 +21,4 @@ local function load() end -- load on startup -load() +minetest.register_on_mods_loaded(load) \ No newline at end of file