Skip to content

Commit

Permalink
Use safe_file_write to save forceloaded blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
sfan5 committed May 30, 2021
1 parent f30dcdb commit 1bc753f
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions builtin/game/forceloading.lua
Expand Up @@ -86,12 +86,6 @@ local function read_file(filename)
return core.deserialize(t) or {}
end

local function write_file(filename, table)
local f = io.open(filename, "w")
f:write(core.serialize(table))
f:close()
end

blocks_forceloaded = read_file(wpath.."/force_loaded.txt")
for _, __ in pairs(blocks_forceloaded) do
total_forceloaded = total_forceloaded + 1
Expand All @@ -106,7 +100,8 @@ end)

-- persists the currently forceloaded blocks to disk
local function persist_forceloaded_blocks()
write_file(wpath.."/force_loaded.txt", blocks_forceloaded)
local data = core.serialize(blocks_forceloaded)
core.safe_file_write(wpath.."/force_loaded.txt", data)
end

-- periodical forceload persistence
Expand Down

0 comments on commit 1bc753f

Please sign in to comment.