diff options
author | hdastwb <hdastwb@hdastwb.heliohost.org> | 2013-08-13 15:53:01 -0400 |
---|---|---|
committer | hdastwb <hdastwb@hdastwb.heliohost.org> | 2013-08-13 15:53:01 -0400 |
commit | 97749578b09f4bb2e9c88d7be569e2c2b72bb881 (patch) | |
tree | 0802bc0fe0513f40a27a8b78fc99d3e45163ea3f /stargate | |
parent | df644d7f7736fce4e92a75d53f44b3df6671ceeb (diff) |
a small fix to not create "empty" stargate files for each player and to clean up such files that already exist
Diffstat (limited to 'stargate')
-rw-r--r-- | stargate/stargate_gui.lua | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/stargate/stargate_gui.lua b/stargate/stargate_gui.lua index f96d48a..ec9fda3 100644 --- a/stargate/stargate_gui.lua +++ b/stargate/stargate_gui.lua @@ -3,7 +3,13 @@ stargate.default_page = "main" stargate_network["players"]={} stargate.current_page={} +local function table_empty(tab) + for key in pairs(tab) do return false end + return true +end + stargate.save_data = function(table_pointer) + if table_empty(stargate_network[table_pointer]) then return end local data = minetest.serialize( stargate_network[table_pointer] ) local path = minetest.get_worldpath().."/stargate_"..table_pointer..".data" local file = io.open( path, "w" ) @@ -22,6 +28,7 @@ stargate.restore_data = function(table_pointer) local data = file:read("*all") stargate_network[table_pointer] = minetest.deserialize( data ) file:close() + if table_empty(stargate_network[table_pointer]) then os.remove(path) end return true else return nil end @@ -31,7 +38,8 @@ end if stargate.restore_data("registered_players") ~= nil then for __,tab in ipairs(stargate_network["registered_players"]) do if stargate.restore_data(tab["player_name"]) == nil then - print ("[stargate] Error loading data!") + --print ("[stargate] Error loading data!") + stargate_network[tab["player_name"]] = {} end end else |