feat(farming/database): switched to built-in craftos functions
This commit is contained in:
@@ -13,12 +13,11 @@ local function listenForFieldDataRequests()
|
||||
while true do
|
||||
local event, _, incomingChannel, replyChannel, message, _ = os.pullEvent("modem_message")
|
||||
if (incomingChannel == fieldDataChannel) then
|
||||
local databaseFile = io.open("/" .. databaseStorage.getMountPath() .. "/field_data.txt", "r")
|
||||
local database = json.decode(databaseFile:read("*a"))
|
||||
local databaseFile = fs.open("/" .. databaseStorage.getMountPath() .. "/field_data.txt", "r")
|
||||
local database = json.decode(databaseFile.readAll())
|
||||
databaseFile.close()
|
||||
|
||||
|
||||
databaseFile:close()
|
||||
databaseFile = nil
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -27,13 +26,12 @@ local function listenForFieldSetups()
|
||||
while true do
|
||||
local event, _, incomingChannel, replyChannel, message, _ = os.pullEvent("modem_message")
|
||||
if (incomingChannel == setupFieldChannel) then
|
||||
local databaseFile = io.open("/" .. databaseStorage.getMountPath() .. "/field_data.txt", "w")
|
||||
local database = json.decode(databaseFile:read("*a"))
|
||||
local databaseFile = fs.open("/" .. databaseStorage.getMountPath() .. "/field_data.txt", "w")
|
||||
local database = json.decode(databaseFile.readAll())
|
||||
|
||||
|
||||
databaseFile:write(json.encode(database))
|
||||
databaseFile:close()
|
||||
databaseFile = nil
|
||||
databaseFile.write(json.encode(database))
|
||||
databaseFile.close()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user