diff --git a/mods/tsm_pyramids/room.lua b/mods/tsm_pyramids/room.lua index 93a8b0f8..f523b947 100755 --- a/mods/tsm_pyramids/room.lua +++ b/mods/tsm_pyramids/room.lua @@ -35,13 +35,20 @@ code["t"] = "trap" function loadchests() local file = io.open(minetest.get_worldpath().."/pyramids_chests.txt","r") - if not file or file:read() == nil then return end - file:seek("set",0) - pyramids.saved_chests = minetest.deserialize(file:read()) - io.close(file) - minetest.log("action","[tsm_pyramids] Chest loaded") + if file then + local saved_chests = minetest.deserialize(file:read()) + io.close(file) + if savetable and type(saved_chests) == "table" then + minetest.log("action","[tsm_pyramids] Chest loaded") + return saved_chests + else + minetest.log("error","[tsm_pyramids] Loading Chest failed") + end + end + return {} end + function savechests() local file = io.open(minetest.get_worldpath().."/pyramids_chests.txt","w") if not file then return end -- should not happen @@ -50,7 +57,7 @@ function savechests() minetest.log("action","[tsm_pyramids] Chests saved") end -loadchests() +pyramids.saved_chests = loadchests() minetest.register_on_shutdown(function() savechests() end)