ravneravn

Save load test

Aug 5th, 2021
774
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. local bot = {}
  3. bot.yStart = 0
  4. bot.currY = 0
  5. bot.currX = 1
  6. bot.currZ = 1
  7. bot.direction = 1
  8. bot.totalLayer = 0
  9. bot.currLayer = 0
  10. bot.valuable = 0
  11. bot.resumeY = 0
  12. bot.resumeX = 0
  13. bot.resumeZ = 0
  14. bot.resumeDirection = 1
  15. bot.isRunning = false
  16. bot.isModem = false
  17. bot.isEnderchest = false
  18. bot.tilesToMine = 0
  19. bot.tilesMined = 0
  20. bot.currentFuel = 0
  21. bot.fuelNeeded = 0
  22. bot.status = "Idle"
  23. bot.blockName = 0
  24. bot.blacklistName = "N/A"
  25.  
  26. local function savePos()
  27.   local fileName = "savedPosition2"
  28.   local handle = fs.open(fileName, "w")
  29.   handle.write(textutils.serialize(bot))
  30.   handle.close()
  31. end
  32.  
  33. local function loadPos()
  34.   local fileName = "savedPosition2"
  35.   if fs.exists(fileName) == true then
  36.     local handle = fs.open(fileName, "r")
  37.     local readFile = handle.readLine()
  38.     if readFile ~= nil then
  39.       bot = textutils.unserialize(readFile)
  40.     end
  41.     handle.close()
  42.   else
  43.     print("file does not exist, check path..")
  44.   end
  45. end
  46.  
  47. print("Original: "..bot.direction)
  48.  
  49. bot.direction = 2
  50. savePos()
  51.  
  52. print("Changed: "..bot.direction)
  53.  
  54. loadPos()
  55.  
  56. print("Loaded: "..bot.direction)
  57.  
RAW Paste Data