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

Tiny problem with a runnable turtle program

Started by TyCamden, 14 October 2012 - 02:47 PM
TyCamden #1
Posted 14 October 2012 - 04:47 PM
If I have a deep hole in the ground and want to fill it, I just stick a block (like glass) on top of it and then place the turtle 1 block in front of the hole. I run the "fill" program and it moves forward, digs out the spot under it, goes down as far as it can, and then fills the hole … ending where it started.

The program works as intended.

But I would like it to fill the hole, whether or not there is glass over the hole or not. There may be… there may not be. I want it to work either way.

As it stands now, When there is glass/a-block on top of the hole, it works perfectly. If there is not, It fills the hole but ends 1 layer too low.

As you can see later on in the code, I tried to fix it. I DIMmed out a section of the code and put replacement code above it. But the fix has no effect.

Help ?


--[[ Program name : fill
	  This program moves 1 forward then
	   moves down to lowest open space and then
	   fills with dirt/etc back up to where it started
	  --]]
--[[ Be sure the turtles has the following items
	  in the correct slots...
	    slot 13 has 64 coal/charcoal
	    other slots (at least 1) has filler (dirt/etc)
	  --]]
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 = 1
--[[ 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 not turtle.down() then
  turtle.digDown()
end
--[[ THIS SECTION IS THE OLD WAY AND IS DIMMED
if turtle.down() == false then
  turtle.digDown()
end
--]]
--[[ move down as far as it can --]]
while not turtle.detectDown() do
  refuel()
  turtle.down()
  downMoves = downMoves + 1
end
--[[ move up and fill --]]
while downMoves > 0 do
  refuel()
  turtle.up()
  while not turtle.placeDown() do
    fillSlot = fillSlot + 1
    if fillSlot == 13 then
	  fillSlot = 14
    end
    turtle.select(fillSlot)
  end
  downMoves = downMoves - 1
end
Doyle3694 #2
Posted 14 October 2012 - 05:08 PM
if not turtle.down() then
  turtle.digDown()
end
Is your problem


if not turtle.down() then
  turtle.digDown()
else
  downMoves = downMoves+1
end
Would fix it
Lettuce #3
Posted 14 October 2012 - 05:13 PM
So… You want it to fill an uncovered hole? Then use this to check:

if not turtle.detectDown() then
--filling code here
end
It will check if there's a hole, then do down and fill it.
TyCamden #4
Posted 14 October 2012 - 07:52 PM
LETTUCE - Thans for the input. However, the program will need to also clear any deep holes covered by 1-layer of something (like glass).

DOYLE3694 - Ah I see ! Yes that was the solution. Thanks :)/>/>

Problem solved.
Doyle3694 #5
Posted 14 October 2012 - 07:54 PM
Glad I could help you :)/>/>