Posted 16 December 2015 - 12:01 AM
I'm having trouble getting this code to work as intended. I'm not getting any error messages, but when I run this navigation program the turtle won't actually move to the specified coords. Not really sure what is wrong here ….any help is appreciated.
Thanks in advance.
Thanks in advance.
xCoord = -6
zCoord = 701
yCoord = 56
orientation = 4
orientations = {"north", "east", "south", "west"}
zDiff = {-1, 0, 1, 0}
xDiff = {0, 1, 0, -1}
function left()
orientation = orientation - 1
orientation = (orientation - 1) % 4
orientation = orientation + 1
turtle.turnLeft()
end
function right()
orientation = orientation - 1
orientation = (orientation + 1) % 4
orientation = orientation + 1
turtle.turnRight()
end
function moveForward()
xCoord = xCoord + xDiff[orientation]
zCoord = zCoord + zDiff[orientation]
turtle.dig()
moved = false
while not(moved) do
moved = turtle.forward()
end
end
function moveUp()
yCoord = yCoord + 1
turtle.digUp()
moved = false
while not(moved) do
moved = turtle.up()
end
end
function moveDown()
yCoord = yCoord - 1
turtle.digDown()
moved = false
while not(moved) do
moved = turtle.down()
end
end
function look(direction)
while direction ~= orientations[orientation] do
right()
end
end
function goto(xTarget, zTarget, yTarget)
while yTarget < yCoord do
moveDown()
end
while yTarget > yCoord do
moveUp()
end
if xTarget < xCoord then
look("west")
while xTarget < xCoord do
moveForward()
end
end
if xTarget > xCoord then
look("east")
while xTarget > xCoord do
moveForward()
end
end
if zTarget < zCoord then
look("north")
while zTarget < zCoord do
moveForward()
end
end
if zTarget > zCoord then
look("south")
while zTarget > zCoord do
moveForward()
end
end
end
goto(-12, 706, 56)
Edited on 16 December 2015 - 12:07 AM