Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local allItems = {}
- local chestCache = {}
- local itemSaveName = "items"
- local chestSaveName = "chests"
- --LOCALS THAT ARE ALREADY IN MAIN
- local dataLocation = "/data/"
- ---------------------------------
- local function save()
- local h = fs.open(dataLocation..itemSaveName,"w")
- if h then
- h.write("return " .. textutils.serialize(allItems))
- h.close()
- else
- printError("Failed to save items to file.")
- end
- h = fs.open(dataLocation..chestSaveName,"w")
- if h then
- h.write("return " .. textutils.serialize(chestCache))
- h.close()
- else
- printError("Failed to save chest data to file.")
- end
- end
- local function load()
- local function dof(loc)
- local ok,err = pcall(dofile,loc)
- if ok then
- return err
- else
- printError("Failed to load items from file "..tostring(loc).." due to "..err)
- end
- return {}
- end
- allItems = dof(dataLocation..itemSaveName)
- chestCache = dof(dataLocation..chestSaveName)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement