Fix saving, add mod.conf. Closes #7.
This commit is contained in:
parent
4f389f287c
commit
fd374c37d2
13
init.lua
13
init.lua
@ -18,9 +18,15 @@ local elevator = {
|
|||||||
motors = {},
|
motors = {},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
local str = minetest.get_mod_storage and minetest.get_mod_storage()
|
||||||
|
|
||||||
local elevator_file = minetest.get_worldpath() .. "/elevator"
|
local elevator_file = minetest.get_worldpath() .. "/elevator"
|
||||||
|
|
||||||
local function load_elevator()
|
local function load_elevator()
|
||||||
|
if str and str:contains("data") then
|
||||||
|
elevator = minetest.deserialize(str:get_string("data"))
|
||||||
|
return
|
||||||
|
end
|
||||||
local file = io.open(elevator_file)
|
local file = io.open(elevator_file)
|
||||||
if file then
|
if file then
|
||||||
elevator = minetest.deserialize(file:read("*all")) or {}
|
elevator = minetest.deserialize(file:read("*all")) or {}
|
||||||
@ -29,10 +35,13 @@ local function load_elevator()
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function save_elevator()
|
local function save_elevator()
|
||||||
local f = io.open(elevator_file .. ".tmp", "w")
|
if str then
|
||||||
|
str:set_string("data", minetest.serialize(elevator))
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local f = io.open(elevator_file, "w")
|
||||||
f:write(minetest.serialize(elevator))
|
f:write(minetest.serialize(elevator))
|
||||||
f:close()
|
f:close()
|
||||||
os.rename(elevator_file .. ".tmp", elevator_file)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
load_elevator()
|
load_elevator()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user