View difference between Paste ID: fJg4z4bQ and dZUW3WH3
SHOW: | | - or go back to the newest paste.
1
local function getFaceTo()
2
  local pos0 = vector.new(gps.locate())
3
  turtle.forward()
4
  local pos1 = vector.new(gps.locate())
5
  local dist = pos1 - pos0
6
  turtle.back()
7
  local faceto = ""
8
  if dist.x > 0 then
9
    faceto = "west"
10
  elseif dist.x < 0 then
11
    faceto = "east"
12
  elseif dist.z > 0 then
13
    faceto = "north"
14
  else
15
    faceto = "south"
16
  end
17
  return faceto
18
end
19
20-
local function forBack(dist)
20+
local function forback(dist)
21
  d = dist
22
  if d < 0 then
23
    d = -d
24
  end  
25-
  for i=1, d do
25+
  if dist > 0 then
26-
    if dist > 0 then
26+
    print("forward:"..tostring(d))
27-
      turtle.forward()
27+
28-
    else
28+
    print("back:"..tostring(d))
29-
      turtle.back()
29+
30-
    end
30+
31
32
local function dispStatus(pos, target, faceto)
33
  print("pos:"..tostring(pos))
34-
local function upDown(dist)
34+
35
  print("dist:"..tostring(target - pos))
36
end
37
38
args = {...}
39-
  for i=1, d do
39+
40-
    if dist > 0 then
40+
41-
      turtle.up()
41+
42-
    else
42+
43-
      turtle.down()
43+
44-
    end
44+
45
curpos = vector.new(gps.locate())
46
47
faceto = getFaceTo()
48-
local function moveAxisX(faceto, curpos, target)
48+
49-
  local dist = target - curpos
49+
dist = target - curpos
50-
  if faceto == "north" then
50+
forback(dist.z)
51-
    turtle.turnLeft()
51+