Advertisement
TheProdigy22

Untitled

Dec 5th, 2020
348
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.74 KB | None | 0 0
  1. local function directionDetection(rows, cols)
  2. local turnRight = false
  3. local trenchlessMode = false
  4. io.write ("Is the turtle on the right or on the left of the field? (r/l)\n")
  5. local direction = io.read()
  6. if direction == "r" or direction == "R" then
  7. turtle.turnRight()
  8. if turtle.forward() then
  9. if not turtle.detect() then
  10. io.write("The Turtle detected no wall around the designated trench. This may mean decreased effeciency or that you've inputted the wrong side. \nProceed? (Y/n)\n")
  11. local check = io.read()
  12. if check == "Y" or check == "y" then
  13. turtle.back()
  14. turtle.turnLeft()
  15. elseif check == "N" or check == "n" then
  16. turtle.back()
  17. turtle.turnLeft()
  18. return directionDetection(rows, cols)
  19. else
  20. io.write("Incorrect input. Restarting.\n")
  21. turtle.back()
  22. turtle.turnLeft()
  23. return directionDetection(rows, cols)
  24. end
  25. else
  26. io.write("Trench detected. Continuing.\n")
  27. turtle.back()
  28. turtle.turnLeft()
  29. end
  30. else
  31. io.write("The Turtle detected a lack of a trench around the bamboo farm. Do you want to activate Trenchless Mode? (Y/n)\n")
  32. turtle.turnLeft()
  33. local check = io.read()
  34. if check == "y" or check == "Y" then
  35. trenchlessMode = true
  36. elseif check == "n" or check == "N" then
  37. return directionDetection(rows, cols)
  38. else
  39. io.write("Incorrect input. Restarting.\n")
  40. return directionDetection(rows, cols)
  41. end
  42. end
  43. turnRight = false
  44. elseif direction == "l" or direction == "L" then
  45. turtle.turnLeft()
  46. if turtle.forward() then
  47. if not turtle.detect() then
  48. io.write("The Turtle detected no wall around the designated trench. This may mean decreased effeciency or that you've inputted the wrong side. \nProceed? (Y/n)\n")
  49. local check = io.read()
  50. if check == "Y" or check == "y" then
  51. turtle.back()
  52. turtle.turnRight()
  53. elseif check == "N" or check == "n" then
  54. turtle.back()
  55. turtle.turnRight()
  56. return directionDetection(rows, cols)
  57. else
  58. io.write("Incorrect input. Restarting.\n")
  59. turtle.back()
  60. turtle.turnRight()
  61. return directionDetection(rows, cols)
  62. end
  63. else
  64. io.write("Trench detected. Continuing.\n")
  65. turtle.back()
  66. turtle.turnRight()
  67. end
  68. else
  69. io.write("The Turtle detected a lack of a trench around the bamboo farm. Do you want to activate Trenchless Mode? (Y/n)\n")
  70. turtle.turnRight()
  71. local check = io.read()
  72. if check == "y" or check == "Y" then
  73. trenchlessMode = true
  74. elseif check == "n" or check == "N" then
  75. return directionDetection(rows, cols)
  76. else
  77. io.write("Incorrect input. Restarting.\n")
  78. return directionDetection(rows, cols)
  79. end
  80. end
  81. turnRight = true
  82. else
  83. io.write("Incorrect input. Restarting.\n")
  84. return directionDetection(rows, cols)
  85. end
  86. checkFuelLevel(rows, cols)
  87. return turnRight, trenchlessMode
  88. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement