Advertisement
Rusettsten

TurnToFace

Nov 30th, 2020 (edited)
700
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.11 KB | None | 0 0
  1. -- A basic turn to face directionality API for DanetOS3
  2. local tArgs = { ... }
  3. if #tArgs ~= 1 then
  4.     print("TurnToFace ERROR: Incorrect Usage. TurnToFace <direction>")
  5.     return
  6. end
  7.  
  8. function readCurDirection()
  9.     local fileData = io.open("danetos3/direction.danet", "r")
  10.     io.input(fileData)
  11.     curDirection = io.read()
  12.     io.close(fileData)
  13.     return(curDirection)
  14. end
  15.  
  16. function turnNorth()
  17.     curDirection = readCurDirection()
  18.     if curDirection == "north" then
  19.         print("SUCCESS! Oriented NORTH.")
  20.     elseif curDirection == "west" then
  21.         shell.run("TurtleTurn right")
  22.         print("SUCCESS! Oriented from WEST to NORTH.")
  23.     elseif curDirection == "south" then
  24.         shell.run("TurtleTurn right")
  25.         shell.run("TurtleTurn right")
  26.         print("SUCCESS! Oriented from SOUTH to NORTH.")
  27.     elseif curDirection == "east" then
  28.         shell.run("TurtleTurn left")
  29.         print("SUCCESS! Oriented from EAST to NORTH.")
  30.     else
  31.         print("TurnToFace ERROR! Invalid direction in direction.danet. It said: " .. curDirection)
  32.     end
  33. end
  34.  
  35. function turnWest()
  36.     curDirection = readCurDirection()
  37.     if curDirection == "west" then
  38.         print("SUCCESS! Oriented WEST.")
  39.     elseif curDirection == "south" then
  40.         shell.run("TurtleTurn right")
  41.         print("SUCCESS! Oriented from SOUTH to WEST.")
  42.     elseif curDirection == "east" then
  43.         shell.run("TurtleTurn right")
  44.         shell.run("TurtleTurn right")
  45.         print("SUCCESS! Oriented from EAST to WEST.")
  46.     elseif curDirection == "north" then
  47.         shell.run("TurtleTurn left")
  48.         print("SUCCESS! Oritented from NORTH to WEST.")
  49.     else
  50.         print("TurnToFace ERROR! Invalid direction in direction.danet. It said: " .. curDirection)
  51.     end
  52. end
  53.  
  54. function turnSouth()
  55.     curDirection = readCurDirection()
  56.     if curDirection == "south" then
  57.         print("SUCCESS! Oriented SOUTH")
  58.     elseif curDirection == "east" then
  59.         shell.run("TurtleTurn right")
  60.         print("SUCCESS! Oriented from EAST to SOUTH.")
  61.     elseif curDirection == "north" then
  62.         shell.run("TurtleTurn right")
  63.         shell.run("TurtleTurn right")
  64.         print("SUCCESS! Oriented from NORTH to SOUTH.")
  65.     elseif curDirection == "west" then
  66.         shell.run("TurtleTurn left")
  67.         print("SUCCESS! Oriented from WEST to SOUTH.")
  68.     else
  69.         print("TurnToFace ERROR! Invalid direction in direction.danet. It said: " .. curDirection)
  70.     end
  71. end
  72.  
  73. function turnEast()
  74.     curDirection = readCurDirection()
  75.     if curDirection == "east" then
  76.         print("SUCCESS! Oritented EAST.")
  77.     elseif curDirection == "north" then
  78.         shell.run("TurtleTurn right")
  79.         print("SUCCESS! Oriented from NORTH to EAST.")
  80.     elseif curDirection == "west" then
  81.         shell.run("TurtleTurn right")
  82.         shell.run("TurtleTurn right")
  83.         print("SUCCESS! Oriented from WEST to EAST.")
  84.     elseif curDirection == "south" then
  85.         shell.run("TurtleTurn left")
  86.         print("SUCCESS! Oriented from SOUTH to EAST.")
  87.     else
  88.         print("TurnToFace ERROR! Invalid direction in direction.danet. It said: " .. curDirection)
  89.     end
  90. end
  91.  
  92. if tArgs[1] == "north" then
  93.     turnNorth()
  94. elseif tArgs[1] == "west" then
  95.     turnWest()
  96. elseif tArgs[1] == "south" then
  97.     turnSouth()
  98. elseif tArgs[1] == "east" then
  99.     turnEast()
  100. else
  101.     print("TurnToFace ERROR: Incorrect args. Must be north, south, east, or west.")
  102. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement