Posted 12 December 2012 - 02:55 PM
function Refuel()
if turtle.getFuelLevel < 20 then
shell.run("refuel",1)
end
end
local tArgs={...}
if #tArgs == 1 then
if tArgs[1] == "base" then
xT = -24 yT = 64 zT = -117
else
print("unknown location")
end
elseif #tArgs == 3 then
local XT=tArgs[1]
local xT=tonumber(XT)
local YT=tArgs[2]
local yT=tonumber(YT)
local ZT=tArgs[3]
local zT=tonumber(ZT)
print(XT,",",YT,",",ZT)
print("XT:"..type(XT))
print("xT:"..","..xT..type(xT))
print("xc:"..xc..type(xc))
else
print("Incorrect Usage")
print("Use goto base or goto <x> <y> <z>")
print("use central computer for more complex goto's")
end
print("target:",xT,",",yT,",",zT)
local xShift = {0,-1,0,1}
local zShift = {1,0,-1,0}
local function checkDir()
facing = facing + 1
look = facing
facing = facing -1
end
local function forward()
while turtle.forward() == false do
turtle.dig()
end
xc = xc+xShift[look]
zc = zc+zShift[look]
end
local function left()
turtle.turnLeft()
facing = facing - 1
if facing == -1 then facing = 3 end
checkDir()
end
local function right()
turtle.turnRight()
facing = facing + 1
if facing == 4 then facing = 0 end
checkDir()
end
function up()
while turtle.up() == false do
turtle.digUp()
end
yc = yc +1
end
local function down()
while turtle.down() == false do
turtle.digDown()
end
yc = yc - 1
end
-----------------------------------------------------------
if xc==-24 and yc==60 and zc==-117 then
rednet.send(5,"release")
sleep(3)
end
for i=0, 12 do
up()
end
if xT<xc then
repeat
left()
until facing == 1
while xT<xc do
forward()
end
elseif xT>xc then
repeat
left()
until facing == 3
while xT>xc do
forward()
end
end
if zT<zc then
repeat
left()
until facing == 2
while zT<zc do
forward()
end
elseif zT>zc then
repeat
left()
until facing == 0
while zT>zc do
forward()
end
end
while yT>yc do
up()
end
while yT<yc do
down()
end
while facing ~= 3 do
left()
end
if tArgs[1] == "base" then
rednet.send(5,"release")
sleep(3)
for i=1,4 do
down()
end
end
if xc==-24 and yc==64 and zc==-117 then
rednet.send(5,"release")
sleep(3)
for i=1,4 do
down()
end
end
problem is:if i run this program from the turtle, specifically with "goto base" it runs absolutely fine.
however when i send the same command over rednet, (i remembered to tostring() and then undo), even though checking with print(type()) xT and xc are both numbers, and neither are nil, ( in this case both are -24) i keep getting an error on line 84 "if xT<xc then" saying goto:84 attempt to compare _ _lt on nil and number
i can't figure it out (this programming has taken much debugging already, this one i just can't find the flaw)
sorry for the n00b coding, any other tips would be great also.
edit: xc,yc and zc are defined by a global variable in the startup