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

Turtle Send To Coordinate [Help!]

Started by TriiCkYHD, 19 December 2013 - 09:11 PM
TriiCkYHD #1
Posted 19 December 2013 - 10:11 PM
I am using the FTB Unleashed pack and I want to setup a mining turtle to use the dig program that we made which tunnels and returns to its starting point but we want to make it so after the turtle tunnels it returns to a set coordinate (BTW im playing on a server I made for my friends if this changes anything) anyway we want the turtle to basically tunnel then return to a set coordinate then refuel, and empty its items into our ME chest which we already setup the refuel and empty thing we just need help with the returning to coordinate so any help is great! Thanks :)/>
bobmandude9889 #2
Posted 19 December 2013 - 11:56 PM
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.