CaptainSpaceCat

varutils

May 20th, 2022 (edited)
162
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. dir = "var/"
  2.  
  3. function save(fn, value)
  4.   local file = fs.open(dir .. fn, "w")
  5.   file.write(tostring(value))
  6.   file.close()
  7. end
  8.  
  9. function load(fn)
  10.   local file = fs.open(dir .. fn, "r")
  11.   local value = file.readAll()
  12.   file.close()
  13.   return value
  14. end
  15.  
  16. function saveTable(fn, table)
  17.   local file = fs.open(dir .. fn,"w")
  18.   file.write(textutils.serialize(table))
  19.   file.close()
  20. end
  21.  
  22. function loadTable(fn)
  23.   local file = fs.open(dir .. fn,"r")
  24.   local data = file.readAll()
  25.   file.close()
  26.   return textutils.unserialize(data)
  27. end
RAW Paste Data Copied