Posted 18 May 2013 - 09:26 AM
i can not seem to get the goto function to work, i did not want to use the gps api for this program. i do have miscperphals so i have the compass module and a teleported in front of the turtle.
pastebin; http://pastebin.com/LMxbrasS and if you are lazy
pastebin; http://pastebin.com/LMxbrasS and if you are lazy
m = peripheral.wrap("front")
c = peripheral.wrap("right")
facing = c.getFacing()
x = 0
y = 0
canMove = false
function canMove()
if turtle.detect() then
return false
else
return true
end
end
function move()
if canMove() then
turtle.forward()
if facing == 0 then
y = y -1
end
if facing == 1 then
x = x +1
end
if facing == 2 then
y = y +1
end
if facing == 3 then
x = x -1
end
end
print("x = "..x.." y = "..y.."")
end
--the turning fuction
function face(f)
facing = c.getFacing()
while facing ~= f do
turtle.turnLeft()
facing = c.getFacing()
end
end
-- move to function
function goto(goX,goY)
--turn at portal
if x ==0 and y == 0 and facing~= 2 then
face(2)
end
--get out of middle
function leaveMiddle()
if goY ~= y or goX ~= x then
if x ~=0 or x ~= 6 and y ~= 15 then
if goX == 6 then
face(3)
else
face(1)
end
end
while x ~= goX do
move()
end
end
end
-- goto right side
if goY ~= y or goX ~= x then
if goX == 6 and x ~= 6 then
if y ~= 3 or y ~= 15 then
if y > 9 then
face(2)
while y ~= 15 do
move()
end
end
if y < 9 and y > 3 then
face(0)
while y ~= 3 do
move()
end
end
if y < 3 then
face(3)
while y < 3 do
move()
end
end
end
end
end
if goY > y and goY ~= y then
face(2)
else
if goY < y and goY ~= y then
face(0)
end
while y ~= goY do
move()
end
end
function getBookOne()
goto(1,1)
end
getBookOne()