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

Question how to make turtle return when done

Started by marshen92, 27 January 2013 - 08:06 PM
marshen92 #1
Posted 27 January 2013 - 09:06 PM
title: Question how to make turtle return when done

Hello all, so i am quite new at this whole computer craft and as such I am unable to make my turtle come back to where it started when it is done

local tArgs = { ... }
if #tArgs ~= 1 then
print( "Usage: torchedtunnel <length>" )
return
end
local length = tonumber( tArgs[1] )
if length < 1 then
print( "Tunnel length must be positive" )
return
end
local function tryRefuel()
    if turtle.getFuelLevel() == 0 then
	    turtle.select(1)
	    turtle.refuel(1)
    end
end
local function tryDig()
    while turtle.detect() == true do
	    turtle.dig()
	    sleep(0.5)
    end
end
local function tryDigUp()
    while turtle.detectUp() == true do
	    turtle.digUp()
	    sleep(0.5)
    end
end
local function tryUp()
    tryDigUp()
    tryRefuel()
    turtle.up()
end
local function tryDown()
    while turtle.detectDown() == true do
	    turtle.digDown()
	    sleep(0.5)
    end
    tryRefuel()
    turtle.down()
end
local function tryForward()
    tryDig()
    tryRefuel()
    turtle.forward()
end
local function makeBridge()
    if turtle.detectDown() == false then
	    turtle.select(2)
	    turtle.placeDown()
    end
end
local count = 1
print( "Tunnelling..." )
for i = 1, length do
    tryForward()
    makeBridge()
    tryDigUp()
    turtle.turnLeft()
    tryDig()
    tryUp()
    tryDig()
    if count % 8 == 0 then
	    turtle.select(3)
	    turtle.place()
    end
    turtle.turnRight()
    turtle.turnRight()
    tryDig()
    tryDown()
    tryDig()
    turtle.turnLeft()
    count = count + 1
end
print( "Returning to start..." )
-- Return to where we started
turtle.select(3)
turtle.place()
turtle.turnLeft()
turtle.turnLeft()
turtle.forward(length)
end

so i am getting an error message saying "bios:338:[ string "ttr" ] :93 :<'eof>' expeced and im not sure how to solve this
and incite on the matter would be wonderful
Cheers
Steve_Dao #2
Posted 28 January 2013 - 09:26 AM
Delete that final 'end'
You get an <'eof'> error when you have an extra end.
Cheers!
remiX #3
Posted 28 January 2013 - 09:43 AM
Change this part



print( "Returning to start..." )
-- Return to where we started
turtle.select(3)
turtle.place()
turtle.turnLeft()
turtle.turnLeft()
turtle.forward(length)
end

to




print( "Returning to start..." )
-- Return to where we started
for i = 1, length do
    turtle.back()
end

So it goes backwards the same amount of times it went forward