You can use the GPS API to get the coordinates of the turtle. Here is the wiki page on it:
http://www.computerc...o/wiki/Gps_(API)
You are going to have to keep track of the direction the turtle is facing yourself though because the GPS API doesn't get the direction the turtle is facing.
To get the amount of blocks you have to move in each direction you can subtract the x pos of the set coordinates - the x pos of the turtle and with the y and z coordinates also.
Here is some example code:
local direction = 3 --#coordinate f in the f3 screen(3 = east) replace with the direction your turtle is facing and change every time it turns
local set_coords = {5,2,8} --#Coords in order x,y,z
local x,y,z = gps.locate() --#attempts to locate turtle and returns x,y,z if located otherwise returns nil. Make sure you have at least 4 gps host computers
if x ~= nil then --# if the turtle was located
local move = {set_coords[1] - x,set_coords[2] - y,set_coords[3] - z} --#gets the distance to be traveled in each direction
if move[1] < 0 then --#if turtle needs to travel backwards on the x coordinate
turtle.turnLeft() --#turns around
turtle.turnLeft()
end
for a = 1,#math.abs(move[1]) do --#Get the absolute value(distance from 0) of the distance it needs to move and loops that many times
turtle.dig() --#digs
turtle.forward() --#moves
end
if move[2] < 0 then --#if turtle needs to travel negative on the y coordinate
turtle.turnLeft() --#it will turn left
else --#otherwise
turtle.turnRight() --#it will turn right
end
for a = 1,math.abs(move[2]) do --#Get the absolute value(distance from 0) of the distance it needs to move and loops that many times
turtle.dig()
turtle.forward()
end
if move[3] < 0 then --#if turtle needs to travel down
for a = 1,math.abs(move[3]) do --#it will travel down
turtle.digDown()
turtle.down()
end
else --#otherwise
for a = 1,math.abs(move[3]) do --#it will travel up
turtle.digUp()
turle.up()
end
end
end
Then you can do basically the same thing to get back to where the turtle was mining
If there are any errors tell me
:)/>
Oh and by the way you could use the built in excavate program. It will mine a specified area and will return to the surface when it is out of fuel or when its inventory is full to drop off items.