• API
• FAQ
• Tools
• Archive
daily pastebin goal
41%
SHARE
TWEET

# Untitled

a guest Feb 13th, 2018 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. -- Set the Turtle home location and heading. X Y Z Heading
2. local home ={382,9,69,0}
3. local facing=4
4.
5. -- Sends the Turtle home, and faces it properly.
6. function goHome()
7.     turtle.select(1)
8.     turtle.refuel()
9.     local startingLocation= gps.locate()
10.     while (startingLocation[2]<(home[2]+1)) do
11.         turtle.up()
12.     end
13.     turtle.refuel()
14.     if facing==4 then
15.         facing=getOrientation()
16.     end
17.     startingLocation=gps.locate()
18.
19.     -- Moves turtle to correct X
20.     if startingLocation[1]~=home[1] then
21.         while facing~= 1 do
22.             turtle.turnLeft()
23.             facing = (facing+1)%4
24.         end
25.         while startingLocation[1]>home[1] do
26.             turtle.forward()
27.         end
28.         while startingLocation[1]<home[1] do
29.             turtle.back()
30.         end
31.     end
32.     -- Moves turtle to correct Z
33.     if startingLocation[3]~=home[3] then
34.         while facing ~= 0 do
35.             turtle.turnLeft()
36.             facing = (facing+1)%4
37.         end
38.         while startingLocation[3]<home[3] do
39.             turtle.forward()
40.         end
41.         while startingLocation[3]>home[3] do
42.             turtle.back()
43.         end
44.     end
45.     -- Sets turtle to correct facing direction
46.     while facing ~= home[4] do
47.         turtle.turnLeft()
48.         facing = (facing+1)%4
49.     end
50.     turtle.down()
51.     print("I am home.")
52. end
53.
54. -- Finds turtle facing direction  North/-z=2 South/+z=0 East/+x=3 West/-x=1
55. function getOrientation()
56.     loc1 = vector.new(gps.locate(2, false))
57.     if not turtle.forward() then
58.         for j=1,6 do
59.             if not turtle.forward() then
60.                     turtle.dig()
61.             else break end
62.         end
63.     end
64.     loc2 = vector.new(gps.locate(2, false))
65.     heading = loc2 - loc1
66.     turtle.back()