Posted 04 September 2012 - 04:43 PM
so i made this goto command for my turtle and it shows an error "bios:48: bad argument: string expected, got nil" i tried finding the problem, but the line 48 only contains
EDIT: Added another Wireless PC, that error gone away, now its "goto:59: attempt to perform arithmetic __sub on nil and string"
line 59:
face = 4
, help please?
local tArgs = {...}
local face = 0
local r = 1
rednet.open("right")
local cx,cy,cz = gps.locate(2,false)
if #tArgs ~= 3 then
print("Incorrect usage of Function.")
print("goto <x> <y> <z>")
else
local gx = tArgs[1]
local gy = tArgs[2]
local gz = tArgs[3]
local x,y,z
function PL()
print("Current Location")
write(cx) write(" ") write(cy) write(" ") print(cz)
print("Destination")
write(gx) write(" ") write(gy) write(" ") print(gz)
print("GOING...")
end
function c_face()
if face == 5 then
face = 1
elseif face == 0 then
face = 4
end
end
function get_Face()
turtle.forward()
while turtle.forward() == false do
turtle.up()
if turtle.up() == false then
turtle.digUp()
end
end
local nx,ny,nz = gps.locate(2,false)
if nx > cx then
face = 1
end
if nx < cx then
face = 4
end
if nz > cz then
face = 3
end
if nz < cz then
face = 2
end
end
function calc()
x = nx - gx
y = ny - gy
z = nz - gz
end
function rotateL()
turtle.turnLeft()
face = face - 1
c_face()
end
function f()
turtle.forward()
while turtle.forward() == false do
turtle.up()
if turtle.up == false then
turtle.digUp()
end
end
end
function go()
calc()
while x > 0 do
if face ~= 1 then
rotateL()
else
f()
x = x - 1
end
end
while x < 0 do
if face ~= 4 then
rotateL()
else
f()
x = x + 1
end
end
while z > 0 do
if face ~= 3 then
rotateL()
else
f()
z = z - 1
end
end
while z < 0 do
if face ~= 2 then
rotateL()
else
f()
z = z + 1
end
end
while y > 0 do
turtle.up()
if turtle.up() == false then
turtle.digUp()
end
end
while y < 0 do
turtle.down()
if turtle.down() == false then
turtle.digDown()
end
end
end
PL()
get_Face()
go()
print(face)
write(nx) write(" ") write(ny) write(" ") print(nz)
write(cx) write(" ") write(cy) write(" ") print(cz)
end
EDIT: Added another Wireless PC, that error gone away, now its "goto:59: attempt to perform arithmetic __sub on nil and string"
line 59:
x = nx - gx