8 posts
Posted 21 November 2012 - 08:20 AM
VIEW LATEST POST FOR UPDATED ERROR
So i saw in a video this dude used a code that checked current X Y and Z coords, and just simply moved the turtle in the correct direction until the numbers for goHome(x, y, z) matched the turtle's coords.
he used
while curLoc.x ~= x do
When I do this it says i'm calling a nil value.
So how do I make a go home script? Please help!
2088 posts
Location
South Africa
Posted 21 November 2012 - 08:52 AM
Well you first have to set up a gps tower and all that. Then store the x y z coords of starting position and store co-ords of the turtle when finished. And then you can do it.
8543 posts
Posted 21 November 2012 - 08:53 AM
Let's see your full code and the full error message.
8 posts
Posted 21 November 2012 - 09:06 AM
Thats the code, error below
turtle.refuel(6)
for i = 1, 3 do
for e 1, 3 do
turtle.dig()
turtle.forward()
end
turtle.turnRight()
turtle.dig()
turtle.forward()
turtle.turnRight()
for i = 1, 3 do
turtle.dig()
turtle.forward()
end
turtle.turnLeft()
turtle.dig()
turtle.forward()
turtle.turnLeft()
for i = 1, 3 do
turtle.dig()
turtle.forward()
end
turtle.turnRight()
turtle.dig()
turtle.forward()
turtle.turnRight()
for i = 1, 3 do
turtle.dig()
turtle.forward()
end
turtle.turnRight()
for i = 1, 3 do
turtle.dig()
turtle.forward()
end
turtle.turnRight()
turtle.digDown()
turtle.down()
--FUNCTIONS
moveHome()
function moveHome()
go(0, 0, 0, 0)
end
function go(x, y, z, f)
while curLoc ~= y do
if curLoc > y then
if turtle.detectDown() then
turtle.digDown()
end
turtle.down()
else
if turtle.detectUp() then
turtle.digUp()
end
turtle.up()
end
end
while curLoc.x ~= x do
if curLoc.x > x then
while curFace ~= 0 do
turtle.turnLeft()
end
else
while curFace ~= 2 do
turtle.turnRight()
end
if turtle.detect() then
turtle.dig()
end
turtle.forward()
end
end
while curLoc.z ~= z do
if curLoc.x > z then
while curFace ~= 1 do
turtle.turnLeft()
end
else
while curFace ~= 3 do
turtle.turnRight()
end
if turtle.detect() then
turtle.dig()
end
turtle.forward()
end
end
while curFace ~= f do
turtle.turnLeft()
end
end
end
error (the program is called "quary")
this worksquary:55: attempt to call nil
8543 posts
Posted 21 November 2012 - 11:12 AM
You need to declare your functions before you try to call them, not after.
8 posts
Posted 21 November 2012 - 12:32 PM
ohhh
thanks my b
8 posts
Posted 21 November 2012 - 12:42 PM
One more problem;
turtle.refuel(6)
for i = 1, 1 do
for e = 1, 3 do
turtle.dig()
turtle.forward()
end
turtle.turnRight()
turtle.dig()
turtle.forward()
turtle.turnRight()
for i = 1, 3 do
turtle.dig()
turtle.forward()
end
turtle.turnLeft()
turtle.dig()
turtle.forward()
turtle.turnLeft()
for i = 1, 3 do
turtle.dig()
turtle.forward()
end
turtle.turnRight()
turtle.dig()
turtle.forward()
turtle.turnRight()
for i = 1, 3 do
turtle.dig()
turtle.forward()
end
turtle.turnRight()
for i = 1, 3 do
turtle.dig()
turtle.forward()
end
turtle.turnRight()
turtle.digDown()
turtle.down()
end
function moveHome()
go(0, 0, 0, 0)
end
function go(x, y, z, f)
while curLoc ~= y do
if curLoc.y > y then
if turtle.detectDown() then
turtle.digDown()
end
turtle.down()
else
if turtle.detectUp() then
turtle.digUp()
end
turtle.up()
end
end
while curLoc.x ~= x do
if curLoc.x > x then
while curFace ~= 0 do
turtle.turnLeft()
end
else
while curFace ~= 2 do
turtle.turnRight()
end
if turtle.detect() then
turtle.dig()
end
turtle.forward()
end
end
while curLoc.z ~= z do
if curLoc.z > z then
while curFace ~= 3 do
turtle.turnRight()
end
else
while curFace ~= 1 do
turtle.turnLeft()
end
if turtle.detect() then
turtle.dig()
end
turtle.forward()
end
while curFace ~= f do
turtle.turnLeft()
end
end
end
moveHome()
ERROR
quary:54: attempt to index ? (a nil value)
818 posts
Posted 21 November 2012 - 12:49 PM
Im not sure if this will give you a bug, but your function is refering to a function that is declared afterwards.
8 posts
Posted 21 November 2012 - 12:58 PM
No thats not it, heres my updated code and updated error:
turtle.refuel(6)
for i = 1, 1 do
for e = 1, 3 do
turtle.dig()
turtle.forward()
end
turtle.turnRight()
turtle.dig()
turtle.forward()
turtle.turnRight()
for i = 1, 3 do
turtle.dig()
turtle.forward()
end
turtle.turnLeft()
turtle.dig()
turtle.forward()
turtle.turnLeft()
for i = 1, 3 do
turtle.dig()
turtle.forward()
end
turtle.turnRight()
turtle.dig()
turtle.forward()
turtle.turnRight()
for i = 1, 3 do
turtle.dig()
turtle.forward()
end
turtle.turnRight()
for i = 1, 3 do
turtle.dig()
turtle.forward()
end
turtle.turnRight()
turtle.digDown()
turtle.down()
end
function go(x, y, z, f)
while curLoc.y ~= y do
if curLoc.y > y then
if turtle.detectDown() then
turtle.digDown()
end
turtle.down()
else
if turtle.detectUp() then
turtle.digUp()
end
turtle.up()
end
end
while curLoc.x ~= x do
if curLoc.x > x then
while curFace ~= 0 do
turtle.turnLeft()
end
else
while curFace ~= 2 do
turtle.turnRight()
end
if turtle.detect() then
turtle.dig()
end
turtle.forward()
end
end
while curLoc.z ~= z do
if curLoc.z > z then
while curFace ~= 3 do
turtle.turnRight()
end
else
while curFace ~= 1 do
turtle.turnLeft()
end
if turtle.detect() then
turtle.dig()
end
turtle.forward()
end
while curFace ~= f do
turtle.turnLeft()
end
end
end
function moveHome()
go(0, 0, 0, 0)
end
moveHome()
ERROR
quary 50: attempt to index ? (a nil value)
8 posts
Posted 21 November 2012 - 02:34 PM
bump
8 posts
Posted 21 November 2012 - 04:58 PM
ehh?
1214 posts
Location
The Sammich Kingdom
Posted 21 November 2012 - 09:20 PM
You should NOT bump your threads constantly.
144 posts
Location
Wellington, New Zealand
Posted 21 November 2012 - 09:30 PM
You haven't declared what curLoc is? Not sure. Is this the full code?
8 posts
Posted 21 November 2012 - 10:56 PM
thats the full code yes. I just copied what the dude on youtube did.
1 posts
Posted 21 November 2012 - 11:25 PM
you need your curloc.* variables to be updated while the turtle is moving. The while loop won't work if it's comparing curloc.* , an undefined variable, against another set of undefined variables, x, y and z.
Make sure every time the turtle moves, it updates the curloc variables in all three directions, whether by using GPS or by making it add and subtract to each of the variables every time it moves. you also need to make sure that the turtle knows where "home" is, so it knows when to stop.