Advertisement
suken27

dig1.lua

Mar 24th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.16 KB | None | 0 0
  1. --[[
  2.     Digging routine for hole expansion
  3. ]]--
  4.  
  5. -- empties inventory and returns to the position it was
  6. function emptyInv()
  7.  
  8. end
  9.  
  10. -- inventory check
  11. function spaceCheck()
  12.     local invSlots = robot.inventorySize()
  13.     for i=1, i<= invSlots, 1 do
  14.         if robot.count(i) == 0 then
  15.             return
  16.         end
  17.     end
  18.     -- if this executes, the inventory is full
  19.     print("Inventory full, going to the storage system.")
  20.     emptyInv()
  21. end
  22.  
  23. -- energy check
  24. function energyCheck()
  25.     local maxEnergy = computer.maxEnergy()
  26.     local energy = computer.energy()
  27.     local minLevel = maxEnergy * 0.1
  28.     if(energy < minLevel) then
  29.         print("Energy low, going to charge.")
  30.         -- TODO returning to the charger
  31.     end
  32. end
  33.  
  34. -- goes to the initial position
  35. function goToInitial()
  36.  
  37. end
  38.  
  39. -- moves to the next position to mine
  40. function move()
  41.    
  42. end
  43.  
  44. -- mines the block upwards or stores the liquid upwards
  45. function mine()
  46.     robot.swingUp()
  47.     robot.drainUp()
  48. end
  49.  
  50. -- main execution
  51. function main()
  52.     goToInitial()
  53.     local end = false
  54.     while(not end)
  55.         energyCheck()
  56.         spaceCheck()
  57.         mine()
  58.         end = move()
  59.     end
  60. end
  61.  
  62. print("Starting digging routine")
  63. main()
  64. print("Ending digging routine")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement