Advertisement
fatboychummy

testing_things

Sep 15th, 2018
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.98 KB | None | 0 0
  1. local allItems = {}
  2. local chestCache = {}
  3.  
  4. local itemSaveName = "items"
  5. local chestSaveName = "chests"
  6.  
  7. --LOCALS THAT ARE ALREADY IN MAIN
  8. local dataLocation = "/data/"
  9.  
  10. ---------------------------------
  11.  
  12.  
  13. local function save()
  14.   local h = fs.open(dataLocation..itemSaveName,"w")
  15.   if h then
  16.     h.write("return " .. textutils.serialize(allItems))
  17.     h.close()
  18.   else
  19.     printError("Failed to save items to file.")
  20.   end
  21.   h = fs.open(dataLocation..chestSaveName,"w")
  22.   if h then
  23.     h.write("return " .. textutils.serialize(chestCache))
  24.     h.close()
  25.   else
  26.     printError("Failed to save chest data to file.")
  27.   end
  28. end
  29.  
  30.  
  31. local function load()
  32.   local function dof(loc)
  33.     local ok,err = pcall(dofile,loc)
  34.     if ok then
  35.       return err
  36.     else
  37.       printError("Failed to load items from file "..tostring(loc).." due to "..err)
  38.     end
  39.     return {}
  40.   end
  41.   allItems = dof(dataLocation..itemSaveName)
  42.   chestCache = dof(dataLocation..chestSaveName)
  43. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement