The problem is in your goTo function, as it calls itself.
function goTo(x,z)
local distanceToTarget = xPos-x+zPos-z
if canRTH() and distanceToTarget+2<turtle.getFuelLevel() then
if z>zPos then
faceForward()
for i=1,z-zPos do
if turtle.detect() then
turtle.dig()
end
moveForward()
if turtle.detectUp() then
turtle.digUp()
end
turtle.suck()
zPos=zPos+1
print("forwards1")
end
end
if z<zPos then
faceBackward()
for i=1,zPos-z do
if turtle.detect() then
turtle.dig()
end
moveForward()
if turtle.detectUp() then
turtle.digUp()
end
turtle.suck()
zPos=zPos-1
print("backwards1")
end
end
if x>xPos then
faceRight()
for i=1,x-xPos do
if turtle.detect() then
turtle.dig()
end
moveForward()
if turtle.detectUp() then
turtle.digUp()
end
turtle.suck()
xPos=xPos+1
print("right1")
end
end
if x<xPos then
faceLeft()
for i=1,xPos-x do
if turtle.detect() then
turtle.dig()
end
moveForward()
if turtle.detectUp() then
turtle.digUp()
end
turtle.suck()
xPos=xPos-1
print("left1")
end
end
else
local lastX,lastZ=xPos,zPos
returnToHome() --# << returnToHome calls goTo, RECURSIVE FUNCTION CALL
print("I need fuel in slot 1, then press enter")
io.read()
turtle.select(1)
turtle.refuel()
print("Resuming..")
goTo(lastX,lastZ) --# <<<< RECURSIVE FUNCTION CALL
end
end
In fact, what I think happens is the turtle has no fuel, so the goTo function calls returnToHome, which calls goTo, which (since you still have no fuel) calls returnToHome... etc.
Edited by KingofGamesYami, 29 July 2016 - 07:32 PM.