netripper

Computercraft - path

Nov 11th, 2018
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.29 KB | None | 0 0
  1. -- path
  2.  
  3. os.loadAPI("dig")
  4.  
  5. --------------
  6. -- PATHING
  7. --------------
  8.  
  9. local path = {}
  10.  
  11. function forward()
  12.   dig.forward()
  13.   path[#path+1] = dig.forward
  14. end
  15.  
  16. function back()
  17.   dig.back()
  18.   path[#path+1] = dig.back
  19. end
  20.  
  21. function down()
  22.   dig.down()
  23.   path[#path+1] = dig.down
  24. end
  25.  
  26. function up()
  27.   dig.up()
  28.   path[#path+1] = dig.up
  29. end
  30.  
  31. function left()
  32.   turtle.turnLeft()
  33.   path[#path+1] = turtle.turnLeft
  34. end
  35.  
  36. function right()
  37.   turtle.turnRight()
  38.   path[#path+1] = turtle.turnRight
  39. end
  40.  
  41. function navigateBack()
  42.   for i=#path,1,-1 do
  43.     if path[i] == dig.forward then dig.back() end
  44.     if path[i] == dig.back then dig.forward() end
  45.     if path[i] == turtle.turnLeft then turtle.turnRight() end
  46.     if path[i] == turtle.turnRight then turtle.turnLeft() end
  47.     if path[i] == dig.up then dig.down() end
  48.     if path[i] == dig.down then dig.up() end
  49.   end
  50. end
  51.  
  52. function navigateForward()
  53.   for i=1,#path do
  54.     path[i]()
  55.   end
  56. end
  57.  
  58. function clear()
  59.   path = {}
  60. end
  61.  
  62. function length()
  63.   return #path
  64. end
  65.  
  66. --------------
  67. --------------
  68. --------------
  69.  
  70. function test()
  71.   clear()
  72.   forward()
  73.   right()
  74.   forward()
  75.   forward()
  76.   right()
  77.   forward()
  78.   left()
  79.   forward()
  80.   up()
  81.   down()
  82.   navigateBack()
  83.   navigateForward()
  84.   navigateBack()
  85. end
Advertisement
Add Comment
Please, Sign In to add comment