From 25a876e788226bbabf47623a910619f0b357ca88 Mon Sep 17 00:00:00 2001 From: crabman77 Date: Thu, 6 Aug 2015 00:26:00 +0200 Subject: [PATCH] fix tsm_pyramids error on load file if file corrupted --- mods/tsm_pyramids/room.lua | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) 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)