My code
term.clear()
local tArgs = {...}
local dx, dy, dz
local dx = tonumber(tArgs[1])
local dy = tonumber(tArgs[2])
local dz = tonumber(tArgs[3])
local x, y, z, dif
local gdcx, gdcy, gdcz
local mm = 1
local curdirec
local xtm, ytm, ztm
local dxn, dyn, dzn
local xn, yn, zn
local zcount = tonumber(0)
local zdestroy = tonumber(0)
local xcount = tonumber(0)
local xdestroy = tonumber(0)
local ytogo = tonumber(0)
local ycount = tonumber(0)
local ydestroy = tonumber(0)
print("Target corrdinents: "..dx)
rednet.open("right")
x, y, z = gps.locate(5)
print("X is equal to "..x)
print("Y is equal to "..y)
print("Z is equal to "..z)
--movement Script
if turtle.forward() then
gdcx, gdcy, gdcz = gps.locate(5)
print("gdcx equal to "..gdcx)
print("gdcy equal to "..gdcy)
print("gdcz equal to "..gdcz)
turtle.back()
else
turtle.dig()
turtle.forward()
gdcx, gdcy, gdcz = gps.locate(5)
print("gdcx equal to "..gdcx)
print("gdcy equal to "..gdcy)
print("gdcz equal to "..gdcz)
turtle.back()
end
--checking Script
if gdcx > x then
curdirec = "4"
print("Current direction: West")
shell.run("left")
print("1")
elseif gdcx < x then
curdirec = "2"
print("Current direction: East")
shell.run("right")
print("1")
elseif gdcz < z then
curdirec = "1"
print("current direction: North")
elseif gdcz > z then
curdirec = "3"
print("Current direction: South")
shell.run("left")
shell.run("left")
else
print("error detected, repeat setup")
end
if dx < 0 then
dxn = 0-dx
--print("debug1:true "..dxn)
else
dxn = dx
--print("debug1.false: "..dxn)
end
if dz < 0 then
dzn = 0-dz
--print("debug2.true: "..dzn)
else
dzn = dz
--print("debug2.false: "..dzn)
end
if x < 0 then
xn = 0-x
--print("debug3.true: "..xn)
else
xn = x
--print("debug3.false : "..xn)
end
if z < 0 then
zn = 0-z
--print("debug4.true: "..zn)
else
zn = z
--print("debug4.false: "..zn)
end
if y < dy then
ytravi = dy - y
ytravdir = 1
elseif y > dy then
ytrav = y - dy
ytravdir = 2
elseif y == dy then
ytrav = 0
ytravdir = 0
else
print("An unknown Error detected! T.T")
end
--move z
if zn < dzn then
ztrav = dzn - zn
ztravdir = 1 -- going to south.
--print("factor1, true "..ztrav)
--rint("factor2, true "..ztravdir)
elseif zn > dzn then
ztrav = zn- dzn
ztravdir = 2 --going to north.
--print("factor1, false "..ztrav)
--print("factor2, true "..ztravdir)
elseif zn == dzn then
ztrav = 0 --going nowhere
ztravdir = 0
else
print("Unknown error!")
end
if ztravdir == 1 then
shell.run("left")
shell.run("left")
for a=1, ztrav do
if turtle.forward() then
zcount = zcount + 1
elseif turtle.up()then
turtle.forward()
print("I moved Up")
zcount = zcount + 0
ytrav = ytrav + 1
else
turtle.digUp()
print("sorry, I Have to dig you..")
zdestroy = zdestroy + 1
end
end
shell.run("left")
shell.run("left")
end
if ztravdir == 2 then
for b=1, ztrav do
if turtle.forward() then
zcount = zcount + 1
elseif turtle.up()then
turtle.forward()
print("I moved Up")
zcount = zcount + 0
else
turtle.digUp()
print("sorry, I Have to dig you..")
zdestroy = zdestroy + 1
end
end
end
if ztraveldir == 0 then
print("I will stay right Here.!")
end
--move x
if xn < dxn then
xtrav = dxn - xn
xtravdir = 1 --going west
elseif x > dxn then
xtrav = xn - dxn
xtravdir = 2 -- going east
elseif xn == dxn then
xtrav = 0
xtravdir = 0
end
print("test "..xtrav)
if xtravdir == 1 then
shell.run("left")
print("1")
for c=1, xtrav do
if turtle.forward() then
xcount = xcount + 1
print("2")
elseif turtle.up()then
turtle.forward()
print("I moved Up")
xcount = xcount + 0
else
turtle.digUp()
print("sorry, I Have to dig you..")
xdestroy = xdestroy + 1
end
end
shell.run("right")
end
if xtravdir == 2 then
shell.run("right")
print("1")
for d=1, xtrav do
if turtle.forward() then
xcount = xcount + 1
print("2")
elseif turtle.up()then
turtle.forward()
print("I moved Up")
xcount = xcount + 0
else
turtle.digUp()
print("sorry, I Have to dig you..")
xdestroy = xdestroy + 1
end
end
shell.run("left")
end
The error says can't find the string xtrav …. It used to work fine, so please help!The error part
if xn < dxn then
xtrav = dxn - xn
xtravdir = 1 --going west
elseif x > dxn then
xtrav = xn - dxn
xtravdir = 2 -- going east
elseif xn == dxn then
xtrav = 0
xtravdir = 0
end
print("test "..xtrav)