Advertisement
Inlife

crystal-growth.lua

Apr 15th, 2024 (edited)
690
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.98 KB | None | 0 0
  1. local FILE_PATH = "storage.dat"
  2. local SLEEP_WAIT = 60
  3. local GROWTH_TIME = 8200 * 1000
  4.  
  5. function getLast()
  6.     if not fs.exists(FILE_PATH) then
  7.          return 0
  8.     end
  9.  
  10.     local file = fs.open(FILE_PATH, "r")
  11.     local contents = file.readAll()
  12.     file.close()
  13.  
  14.     return tonumber(contents)
  15. end
  16.  
  17. function setLast(value)
  18.     local file = fs.open(FILE_PATH, "w")
  19.     file.write("" .. value)
  20.     file.close()
  21. end
  22.  
  23. function iterate()
  24.     print("[cr] waiting for growth ...")
  25.     while (os.epoch("utc") - getLast()) < GROWTH_TIME do
  26.         sleep(SLEEP_WAIT)
  27.     end
  28.  
  29.     print("[cr] growth assumed to be finished!")
  30.     setLast(os.epoch("utc"))
  31.     redstone.setOutput("back", true)
  32.     sleep(2)
  33.     redstone.setOutput("back", false)
  34. end
  35.  
  36. function main()
  37.     print("\n\n-------------------------------")
  38.     print("[cr] starting the program; v1.0")
  39.     print("-------------------------------\n\n");
  40.  
  41.     while true do
  42.         iterate()
  43.     end
  44. end
  45.  
  46. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement