Advertisement
Liktorn

control

May 11th, 2014
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.90 KB | None | 0 0
  1. local controlChest = peripheral.wrap("front")
  2.  
  3. -- variable for mining lenght
  4. local time = 0
  5. local number = true
  6.  
  7.  
  8. -- The following function rounds a number to the given number of decimal places.
  9. function round(num, idp)
  10.   local mult = 10^(idp or 0)
  11.   return math.floor(num * mult + 0.5) / mult
  12. end
  13.  
  14. -- how long to mine
  15. print("How long time would you like to mine in minutes:")
  16. time = assert(tonumber(read()),"input is not a number")
  17. print("To abort the operation")
  18. print("hold ENTER")
  19.  
  20.  
  21. --if number == false then
  22. --  return
  23. --else
  24. -- calculate the time to seconds
  25.   time = time * 60
  26. --end
  27.  
  28. -- put an item in the chest
  29. -- and sleep for selected time
  30. turtle.select(1)
  31. turtle.drop()
  32.  
  33.  
  34. local on = true
  35. local interval = 0.5
  36. local timer = os.startTimer(0)
  37.  
  38. while time > 0 do
  39.     --sleep(1)
  40.  
  41.  
  42.  
  43.  
  44.     -- if we want the miner to quit early then press enter
  45.     -- this part of the code is from billysback
  46.     local event, p1, p2, p3 = os.pullEvent()
  47.     if event == "timer" then
  48.         --Update program
  49.  
  50.         sleep(0.5)
  51.         -- print the time left, but only the whole minutes
  52.         -- and only once a minute
  53.         -- if time is evenly divided by 60 (that is woth no riminder)
  54.         if (time % 60) == 0 then
  55.             print("Time left: " ..math.floor(time/60).. " minutes")
  56.         end
  57.         --print("Time left: " ..time.. " ticks")
  58.         time = time  - 1
  59.  
  60.         timer = os.startTimer(interval)
  61.     else
  62.         local key = p1
  63.         if key == 28 then --enter
  64.             on = false
  65.             break
  66.         end
  67.     end
  68.  
  69.  
  70.  
  71.    
  72. --[[
  73.     sleep(1)
  74.     -- print the time left, but only the whole minutes
  75.     -- and only once a minute
  76.     -- if time is evenly divided by 60 (that is woth no riminder)
  77.     if (time % 60) == 0 then
  78.         print("Time left: " ..math.floor(time/60).. " minutes")
  79.     end
  80.     --print("Time left: " ..time.. " ticks")
  81.     time = time  - 1
  82.  
  83. ]]
  84. end
  85.  
  86. -- put it back into the turtle to end the mining session
  87. controlChest.pushItem("south",1,64,1)
  88.  
  89. -- print that it's done
  90. print("DONE!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement