Advertisement
Guest User

tst

a guest
Aug 21st, 2014
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.39 KB | None | 0 0
  1. -- Turtle Self-tracking System created by Arclight306
  2. function startup()
  3.   local xPos, yPos, zPos = nil
  4.   local face = nil
  5.   local cal = false
  6. end
  7.  
  8. function gpsLocation(facing) -- get gps using other computers
  9.    xPos, yPos, zPos = gps.locate()
  10.    if xPos == nil then
  11.       cal = false
  12.       return false
  13.    else
  14.       if facing == "north" or facing == "east" or facing == "south" or facing == "west" then
  15.          face = facing
  16.          cal = true
  17.          return true
  18.       else
  19.          cal=false
  20.          assert(false, "Facing must be north, south, east or west")
  21.       end
  22.       return false
  23.    end
  24. end
  25.  
  26. function setLocation(x, y, z, facing) -- manually set location
  27.    
  28.    assert(type(x) == "number", "x must be a number")
  29.    assert(type(y) == "number", "y must be a number")
  30.    assert(type(z) == "number", "z must be a number")
  31.        
  32.    if facing == "north" or facing == "east" or facing == "south" or facing == "west" then
  33.       face = facing
  34.       cal = true
  35.    else
  36.       cal=false
  37.       assert(false, "Facing must be north, south, east or west")
  38.    end
  39.    
  40.    xPos = x
  41.    yPos = y
  42.    zPos = z
  43.    face = facing
  44. end
  45.  
  46. function getLocation() -- return the location
  47.    if xPos ~= nil then
  48.       return xPos, yPos, zPos, face
  49.    elseif xPos == nil then
  50.       return nil
  51.    end
  52. end
  53.  
  54. function turnLeft() -- turn left
  55.    if(turtle.turnLeft()) then
  56.       if face == "north" then
  57.          face = "west"
  58.       elseif face == "west" then
  59.          face = "south"
  60.       elseif face == "south" then
  61.          face = "east"
  62.       elseif face == "east" then
  63.          face = "north"
  64.       end
  65.       return true
  66.    end
  67.    return false
  68. end
  69.  
  70. function turnRight() -- turn right
  71.    if(turtle.turnRight()) then
  72.       if face == "north" then
  73.          face = "east"
  74.       elseif face == "east" then
  75.          face = "south"
  76.       elseif face == "south" then
  77.          face = "west"
  78.       elseif face == "west" then
  79.          face = "north"
  80.       end
  81.       return true
  82.    end
  83.    return false
  84. end
  85.  
  86. function forward() -- go forward
  87.  
  88.    if(turtle.forward()) then
  89.       if cal == true then
  90.          if face == "north" then
  91.             zPos = zPos - 1
  92.          elseif face == "west" then
  93.             xPos = xPos - 1
  94.          elseif face == "south" then
  95.             zPos = zPos + 1
  96.          elseif face == "east" then
  97.             xPos = xPos + 1
  98.          end
  99.       else
  100.          print("Not Calibrated.")
  101.       end
  102.       return true
  103.    end
  104.    return false
  105. end
  106.  
  107. function back() -- go back
  108.  
  109.    if(turtle.back()) then
  110.       if cal == true then
  111.          if face == "north" then
  112.             zPos = zPos + 1
  113.          elseif face == "west" then
  114.             xPos = xPos + 1
  115.          elseif face == "south" then
  116.             zPos = zPos - 1
  117.          elseif face == "east" then
  118.             xPos = xPos - 1
  119.          end
  120.       else
  121.          print("Not Calibrated.")
  122.       end
  123.       return true
  124.    else
  125.       return false
  126.    end
  127. end
  128.  
  129. function up() -- go up
  130.    if(turtle.up()) then
  131.       if cal == true then
  132.          yPos = yPos + 1
  133.       else
  134.          print("Not Calibrated.")
  135.       end
  136.       return true
  137.    else
  138.       return false
  139.    end
  140. end
  141.  
  142. function down() -- go down
  143.    if(turtle.down()) then
  144.       if cal == true then
  145.          yPos = yPos - 1
  146.       else
  147.          print("Not Calibrated.")
  148.       end
  149.       return true
  150.    else
  151.       return false
  152.    end
  153. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement