Posted 15 March 2013 - 05:40 AM
I've pretty much got the code down. it might have a few errors I haven't found yet but one thing that I just thought of is. when script is running how do I get it to get the x y z cords from a rednet message or is what I have sufficient? I don't think it is as I'd need some kind of loop until it can get the cords to go to.
Here's my code:
Here's my code:
Spoiler
-- Turtle Call
-- Check for gps cords and location to go to.
local BF() = turtle.detect
local BU() = turtle.detectUp
local BD() = turtle.detectDown
local ID, a, b, c = rednet.receive()
local x, y, z = gps.locate(60)
local fuel() = turtle.getFuelLevel
rednet.open("right")
if x == nil then
rednet.broadcast("No GPS found aborting operation")
exit()
else
turtle.refuel(all)
if fuel() < 10 then
rednet.broadcast("Fuel level low")
rednet.broadcast("Aporting operation")
rednet.broadcast("Currently at" .. x .. y .. z)
exit()
else
rednet.broadcast("Currently at" .. x .. y .. z)
rednet.broadcast("Moving to" .. a .. b .. c)
end
end
--Moving turtle down/up
while not y == b do
local x, y, z = gps.locate(60)
if y < b then
if fuel() > 0 then
if BU() = true then
turtle.digUp()
else
turtle.up()
end
else
rednet.broadcast("Out of Fuel")
rednet.broadcast("Aporting operation")
rednet.broadcast("Currently at" .. x .. y .. z)
exit()
end
end
if y > b then
if fuel() > 0 then
if BD() = true then
turtle.digDown()
else
turtle.down()
end
else
rednet.broadcast("Out of Fuel")
rednet.broadcast("Aporting operation")
rednet.broadcast("Currently at" .. x .. y .. z)
exit()
end
end
end
-- Moving turtle on x axis and getting orientation
if fuel() < 10 then
local x, y, z = gps.locate(60)
rednet.broadcast("Fuel level low")
rednet.broadcast("Aporting operation")
rednet.broadcast("Currently at" .. x .. y .. z)
exit()
end
while not xmath == 1 do
local x, y, z = gps.locate(10)
local firstx = vector.new(x)
while not turtle.forward() do turtle.dig() end
local x, y, z = gps.locate(10)
local secondx = vector.new(x)
local xmath = firstx:sub(secondx)
if xmath == 0 then
turtle.turnLeft()
else
turtle.turnLeft()
turtle.turnLeft()
local xmath = 0
end
end
if x > a then
turtle.turnLeft()
turtle.turnLeft()
end
while not x == a do
local x, y, z = gps.locate(60)
if x < a then
if fuel() > 0 then
if BF() = true then
turtle.dig()
else
turtle.forward()
end
else
rednet.broadcast("Out of Fuel")
rednet.broadcast("Aporting operation")
rednet.broadcast("Currently at" .. x .. y .. z)
exit()
end
end
if x > a then
if fuel() > 0 then
if BF() = true then
turtle.dig()
else
turtle.forward()
end
else
rednet.broadcast("Out of Fuel")
rednet.broadcast("Aporting operation")
rednet.broadcast("Currently at" .. x .. y .. z)
exit()
end
end
end
-- Moving turtle on z axis and getting orientation
if fuel() < 10 then
local x, y, z = gps.locate(60)
rednet.broadcast("Fuel level low")
rednet.broadcast("Aporting operation")
rednet.broadcast("Currently at" .. x .. y .. z)
exit()
end
turtle.turnLeft()
while not zmath == 1 do
local x, y, z = gps.locate(10)
local firstz = vector.new(z)
while not turtle.forward() do turtle.dig() end
local x, y, z = gps.locate(10)
local secondz = vector.new(z)
local zmath = firstz:sub(secondz)
if zmath == 0 then
turtle.turnLeft()
else
turtle.turnLeft()
turtle.turnLeft()
local zmath = 0
end
end
if z > c then
turtle.turnLeft()
turtle.turnLeft()
end
while not z == c do
local x, y, z = gps.locate(60)
if z < c then
if fuel() > 0 then
if BF() = true then
turtle.dig()
else
turtle.forward()
end
else
rednet.broadcast("Out of Fuel")
rednet.broadcast("Aporting operation")
rednet.broadcast("Currently at" .. x .. y .. z)
exit()
end
end
if z > c then
if fuel() > 0 then
if BF() = true then
turtle.dig()
else
turtle.forward()
end
else
rednet.broadcast("Out of Fuel")
rednet.broadcast("Aporting operation")
rednet.broadcast("Currently at" .. x .. y .. z)
exit()
end
end
end