i'me making a move api / psudo-class to make my turtle get around a bit easier , and making them a little smarter about getting to a place than go up X go forward Y and so on, i have it setup so it will store relitive or if set , global positioning and move to that location. but when an obstical is in the way it should stop trying to go that way and try moving in one of the other posible directions it needs to go to get to the destination. currently it kinda does that. it will try and take another path, but never go back and try to finish the other direction.
it would be great if i could have some one look over my code and try to fix it ^^;
same code here for easy turtle copying http://pastebin.com/zLJDCC10
move = {
direction = 0,
currentX = -1,
currentY = -1,
currentZ = -1,
persistant = true,
gps = false
}
function move.init()
return move
end
function init()
return move
end
-- 0 = z+
-- 2 = z-
-- 1 = x-
-- 3 = x+
function move.to(x,y,z)
xmoves = move.currentX + x
ymoves = move.currentY + y
zmoves = move.currentZ + z
print(xmoves .." ".. ymoves .." "..zmoves)
while xmoves ~= 0 or ymoves ~= 0 or zmoves ~= 0 do
xstuck = false
ystuck = false
zstuck = false
print(xmoves .." ".. ymoves .." "..zmoves)
if ymoves < 0 then
print("ymoves less than 0")
while ystuck == false and ymoves ~= 0 do
if turtle.down() then
move.currentY = move.currentY - 1
ymoves = ymoves + 1
else
ystuck = true
end
end
end
if xmoves > 0 then
print("xmoves greater than 0")
move.face(3)
while xstuck == false and xmoves ~= 0 do
if turtle.forward() then
move.currentX = move.currentX + 1
xmoves = xmoves - 1
else
xstuck = true
end
end
elseif xmoves < 0 then
print("xmoves less than 0")
move.face(1)
while xstuck == false and xmoves ~= 0 do
if turtle.forward() then
move.currentX = move.currentX - 1
xmoves = xmoves + 1
else
xstuck = true
end
end
end
if zmoves > 0 then
print("zmoves greater than 0")
move.face(2)
while zstuck == false and zmoves ~= 0 do
if turtle.forward() then
move.currentZ = move.currentZ - 1
zmoves = zmoves - 1
else
zstuck = true
end
end
elseif zmoves < 0 then
print("zmoves less than 0")
move.face(0)
while zstuck == false and zmoves ~= 0 do
if turtle.forward() then
move.currentZ = move.currentZ + 1
zmoves = zmoves + 1
else
zstuck = true
end
end
end
if ymoves > 0 then
print("ymoves greater than 0")
while ystuck == false and ymoves ~= 0 do
if turtle.up() then
move.currentY = move.currentY + 1
ymoves = ymoves - 1
else
ystuck = true
end
end
end
end
zmoves = 0
xmoves = 0
ymoves = 0
end
function move.face(f)
if plus(move.direction,1) == f then
turtle.turnRight()
move.direction = plus(move.direction,1)
elseif minus(move.direction,1) == f then
turtle.turnLeft()
move.direction = minus(move.direction,1)
elseif f == move.direction then
-- -_-/> really?
else
turtle.turnLeft()
turtle.turnLeft()
move.direction = minus(move.direction,2)
end
end
-- directional math
function minus(x,y)
if x - y < 0 then
r2 = 0
for r1=x-y,0,1 do
r2 = r2 + 1
end
return 4-r2
else
return x-y
end
end
function plus(x,y)
if x + y > 3 then
r = x+y
while r > 3 do
r = r - 4
end
return r
else
return x+y
end
end