This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Clayguy247's profile picture

Turtle GO HOME Help!

Started by Clayguy247, 21 November 2012 - 07:20 AM
Clayguy247 #1
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!
remiX #2
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.
Lyqyd #3
Posted 21 November 2012 - 08:53 AM
Let's see your full code and the full error message.
Clayguy247 #4
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
Lyqyd #5
Posted 21 November 2012 - 11:12 AM
You need to declare your functions before you try to call them, not after.
Clayguy247 #6
Posted 21 November 2012 - 12:32 PM
ohhh
thanks my b
Clayguy247 #7
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)
Doyle3694 #8
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.
Clayguy247 #9
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)
Clayguy247 #10
Posted 21 November 2012 - 02:34 PM
bump
Clayguy247 #11
Posted 21 November 2012 - 04:58 PM
ehh?
Sammich Lord #12
Posted 21 November 2012 - 09:20 PM
You should NOT bump your threads constantly.
Zoinky #13
Posted 21 November 2012 - 09:30 PM
You haven't declared what curLoc is? Not sure. Is this the full code?
Clayguy247 #14
Posted 21 November 2012 - 10:56 PM
thats the full code yes. I just copied what the dude on youtube did.
relentlessfiend #15
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.