This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
TyCamden's profile picture

Very simple program will go down but will not return to me properly

Started by TyCamden, 12 October 2012 - 01:21 PM
TyCamden #1
Posted 12 October 2012 - 03:21 PM
Re: Very simple program will go down but will not return to me properly

I have a large mined pit in front of me (from an old quarry) and it is covered with a layer of glass on top.

I want a turtle to move onto the glass, dig one out, then just move to the bottom and come back up. (I will add the "fill hole with dirt as it comes up" part later).

So I run it, and it goes to the bottom (I think) but it only comes halfway back up.

Help ?


--[[ Program name : testmovedown
	  this program moves forward 1 then
	  digs below if necessary once then
	  moves down as far as it can then
	  moved back up to starting position
	  --]]
--[[ Be sure the turtle has...
	    slot 13 has 64 coal/charcoal
	  --]]
function refuel()
  fuellvl = turtle.getFuelLevel()
  if fuellvl<100 then
    amtchar = turtle.getItemCount(13)
    if amtchar > 1 then
	  turtle.select(13)
	  turtle.refuel(2)
	  turtle.select(1)
    else
	  if amtchar > 0 then
	    turtle.select(13)
	    turtle.refuel(1)
	    turtle.select(1)
	  end
    end
  end
end
--[[ set numeric var's --]]
fuellvl = 0
amtchar = 0
downMoves = 0
X = 0
fillSlot = 0
--[[ move forward one --]]
refuel()
turtle.forward()
--[[ for first move, it might have to dig through something
	   as I may have sealed a deep hole --]]
if turtle.down() == false then
  turtle.digDown()
end
--[[ move down as far as it can --]]
while turtle.down() do
  refuel()
  turtle.down()
  downMoves = downMoves + 1
end
--[[ move back up --]]
while downMoves > 0 do
  refuel()
  turtle.up()
  downMoves = downMoves - 1
end
Ditto8353 #2
Posted 12 October 2012 - 03:46 PM
while turtle.down() do
refuel()
turtle.down()
downMoves = downMoves + 1
end

This moves the turtle down twice, but only increments once. Use this instead.

while not turtle.detectDown() do
refuel()
turtle.down()
downMoves = downMoves + 1
end
TyCamden #3
Posted 13 October 2012 - 01:48 AM
Thanks! I didn't realize this. This really helps a lot.

If possible (if u have time), can u help me with the problem on the following thread?
http://www.computercraft.info/forums2/index.php?/topic/4902-turtle-going-in-a-circle-but-should-not/