Advertisement
Selim_042

turtleCarAPI

Feb 26th, 2015
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.82 KB | None | 0 0
  1. function getDir(compass)
  2.   compass = peripheral.find("compass")
  3.   dir = compass.getFacing()
  4.   return dir
  5. end
  6.  
  7. function getCoords()
  8.   coords = {}
  9.   xFile = fs.open("coords/x", "r")
  10.   coords[1] = xFile.readAll()
  11.   xFile.close()
  12.   yFile = fs.open("coords/y", "r")
  13.   coords[2] = yFile.readAll()
  14.   yFile.close()
  15.   zFile = fs.open("coords/z", "r")
  16.   coords[3] = zFile.readAll()
  17.   zFile.close()
  18.   return coords
  19. end
  20.  
  21. function writeCoords(coords)
  22.   xFile = fs.open("coords/x", "w")
  23.   coords[1] = xFile.write(coords[1])
  24.   xFile.close()
  25.   yFile = fs.open("coords/y", "w")
  26.   coords[2] = yFile.write(coords[2])
  27.   yFile.close()
  28.   zFile = fs.open("coords/z", "w")
  29.   coords[3] = zFile.write(coords[3])
  30.   zFile.close()
  31. end
  32.  
  33. function left()
  34.   turtle.turnLeft()
  35.   dir = turtleCar.getDir()
  36. end
  37.  
  38. function right()
  39.   turtle.turnRight()
  40.   dir = turtleCar.getDir()
  41. end
  42.  
  43. function forward(num)
  44.   while (num > 0) do
  45.     if turtle.forward() then
  46.       if dir == "north" then
  47. --        coords[3] = coords[3] - 1
  48.       elseif dir == "south" then
  49. --        coords[3] = coords[3] + 1
  50.       elseif dir == "east" then
  51. --        coords[1] = coords[1] + 1
  52.       elseif dir == "west" then
  53. --        coords[1] = coords[1] - 1
  54.       end
  55.     end
  56.   num = num - 1
  57.   end
  58. end
  59.  
  60. function backward(num)
  61.   while (num > 0) do
  62.     if turtle.back() then
  63.       if dir == "north" then
  64. --        coords[3] = coords[3] + 1
  65.       elseif dir == "south" then
  66. --        coords[3] = coords[3] - 1
  67.       elseif dir == "east" then
  68. --        coords[1] = coords[1] - 1
  69.       elseif dir == "west" then
  70. --        coords[1] = coords[1] + 1
  71.       end
  72.     end
  73.   num = num - 1
  74.   end
  75. end
  76.  
  77. function up()
  78.   if turtle.up() then
  79. --    coords[2] = coords[2] + 1
  80.   end
  81. end
  82.  
  83. function down()
  84.   if turtle.down() then
  85. --    coords[2] = coords[2] - 1
  86.   end
  87. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement