Advertisement
dealingwith

ComputerCraft Turtle Starter Code

Feb 8th, 2015
340
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.36 KB | None | 0 0
  1. function fuel()
  2.   if turtle.getFuelLevel() < 30 then
  3.     turtle.select(1)
  4.     if turtle.refuel(1) then
  5.       return true
  6.     end
  7.     print("Refuelling failed.")
  8.     return false
  9.   end
  10. end
  11.  
  12. function right()
  13.   turtle.turnRight()
  14. end
  15.  
  16. function left()
  17.   turtle.turnLeft()
  18. end
  19.  
  20. function forward()
  21.   while not turtle.forward() do
  22.     if not turtle.dig() then
  23.       turtle.attack()
  24.     end
  25.   end
  26. end
  27.  
  28. function shiftRight()
  29.   right()
  30.   forward()
  31.   left()
  32. end
  33.  
  34. function shiftLeft()
  35.   left()
  36.   forward()
  37.   right()
  38. end
  39.  
  40. function shiftNRight(n)
  41.   right()
  42.   for i=1,n,1 do
  43.     forward()
  44.   end
  45.   left()
  46. end
  47.  
  48. function shiftNLeft(n)
  49.   left()
  50.   for i=1,n,1 do
  51.     forward()
  52.   end
  53.   right()
  54. end
  55.  
  56. function dig()
  57.   if turtle.detect() then
  58.     turtle.dig()
  59.   end
  60. end
  61.  
  62. function dump(start_point,end_point)
  63.   for i=start_point,end_point,1 do
  64.     turtle.select(i)
  65.     turtle.drop()
  66.   end
  67. end
  68.  
  69. function find(id)
  70.   for i=1,16,1 do
  71.     local data = turtle.getItemDetail(i)
  72.     if data and data.name == id then
  73.       return i
  74.     end
  75.   end
  76.   return 0
  77. end
  78.  
  79. function turnAround()
  80.   right()
  81.   right()
  82. end
  83.  
  84. function fif(val, a, b)
  85.   if val then a() else b() end
  86. end
  87.  
  88. function fifFlip(val, a, b)
  89.   if val then a() else b() end
  90.   return not val
  91. end
  92.  
  93. function move(len)
  94.   for i=1,len,1 do
  95.     fuel()
  96.     forward()
  97.   end
  98. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement