Posted 30 July 2016 - 05:46 PM
I have written an API (trackMove) for tracking turtle location in cartesian coordinates. I have run into some issues while utilizing it in a program I have written to dig a rectangular room (digRoom).
In digRoom, the turtle stops mining and returns to the chest to empty it's inventory when all slots are occupied. In order to allow the turtle to return to the location it stopped at, I save its current location to instance variables before returning. The excerpt below is from this portion of digRoom:
After the turtle failed to return to the correct position, I added the print statements above to troubleshoot. Both consistently print the location of the turtle as (0, 0, 0) regardless its actual location. Digging deeper, I added a print statement in trackMove.
This resulted in the correct location being printed out every time the turtle moves forward (including when the other statement prints "0, 0, 0") until the turtle gets back to the chest and empties its inventory. From there, its z value if off by +1.
I assume the z error is a logic mistake that I will be able to fix, but the failure of digRoom to save the current location of the turtle in order to return has me perplexed. The full code can be found at my github here: https://github.com/dcmid/ComputerCraft
In digRoom, the turtle stops mining and returns to the chest to empty it's inventory when all slots are occupied. In order to allow the turtle to return to the location it stopped at, I save its current location to instance variables before returning. The excerpt below is from this portion of digRoom:
if shouldReturn() then
tempX = trackMove.xCoord
tempY = trackMove.yCoord
tempZ = trackMove.zCoord
tempO = trackMove.orientation
print("Temp Coords: " .. tempX .. ", " .. tempY .. ", " .. tempZ .. ", " .. tempO)
returnToOrigin()
print(trackMove.xCoord .. ", " .. trackMove.yCoord .. ", " .. trackMove.zCoord .. ", " .. trackMove.orientation)
if not chestDump() then
return
end
trackMove.gotoX(tempX)
trackMove.gotoY(tempY)
trackMove.gotoZ(tempZ)
trackMove.orientTo(tempO)
end
After the turtle failed to return to the correct position, I added the print statements above to troubleshoot. Both consistently print the location of the turtle as (0, 0, 0) regardless its actual location. Digging deeper, I added a print statement in trackMove.
function mine()
genDig.mine()
if orientation == 0 then
zCoord = zCoord + 1
elseif orientation == 1 then
xCoord = xCoord + 1
elseif orientation == 2 then
zCoord = zCoord - 1
else
xCoord = xCoord - 1
end
print("Current Position: " .. xCoord .. ", " .. yCoord .. ", " .. zCoord .. ", " .. orientation)
return
end
This resulted in the correct location being printed out every time the turtle moves forward (including when the other statement prints "0, 0, 0") until the turtle gets back to the chest and empties its inventory. From there, its z value if off by +1.
I assume the z error is a logic mistake that I will be able to fix, but the failure of digRoom to save the current location of the turtle in order to return has me perplexed. The full code can be found at my github here: https://github.com/dcmid/ComputerCraft