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

Quarry hole remover

Started by madbrad21, 27 March 2013 - 04:19 AM
madbrad21 #1
Posted 27 March 2013 - 05:19 AM
Hello,
I'm very new to programming and I am trying to write a program to fill in the top layer of a quarry. So far I can get it to place the first row of blocks, but for some reason it won't run it's second part. I think it has to do with the if then for blockDown and noblockDown but I'm not sure what I need to change since it's useing a Boolean string my only choices are true/false.

function needsFuel()
	  if turtle.getFuelLevel() < 10 then
		return true
	  else
		return false
	  end
	end

	function refuel()
	  turtle.select(16)
	  turtle.refuel(1)
	end

	function invCheck()
	  for slot = 1, 15 do
		if turtle.getItemCount(slot) == 0 then
		  slot = slot + 1
		  turtle.select(slot)
		 end
	  end
	end

	function noblockDown()
	  while turtle.detectDown() == false do
		invCheck()
		turtle.placeDown()
		turtle.forward()
	  end
	end

	function blockDown()
	  while turtle.detectDown() ~= false do
		turtle.turnRight()
		turtle.forward()
		turtle.turnRight()
		turtle.forward()
		turtle.turnLeft()
	  end
	end

	function fill()
	  if needsFuel() then
		refuel()
	  end
	  if noblockDown() == false then
	   blockDown()
	  end
	end
	 turtle.select(1)
	while true do
	  fill()
	end

also here's a pastebin link [html]http://pastebin.com/GpeQWDAp[/html]

Edit: I forgot to mention that when I combine the noblockDown() and blockDown() it gives the error "filler:2: Too long without yielding
Alekso56 #2
Posted 27 March 2013 - 07:02 AM
You aren't making noblockDown() return anything to fill()……
madbrad21 #3
Posted 27 March 2013 - 01:50 PM
Thanks, I feel stupid now. I looked over the code for quite a while. at any rate the new code:

function needsFuel()
  if turtle.getFuelLevel() < 10 then
    return true
  else
    return false
  end
end
 
function refuel()
  turtle.select(16)
  turtle.refuel(1)
end

function invCheck()
  for slot = 1, 15 do
    if turtle.getItemCount(slot) == 0 then
	  slot = slot + 1
	  turtle.select(slot)
	 end
  end
  if turtle.getItemCount(15) == 1 then
    print("Feed Me!")
    os.pullEvent(key)
    turtle.placeDown()
  end
end

function blockDown()
  while turtle.detectDown() == true do
    print("Finding Hole")
    turtle.turnRight()
    turtle.forward()
    turtle.turnRight()
    turtle.forward()
    turtle.turnLeft()
  end
end

function noblockDown()
  if turtle.detectDown() == false then
    turtle.select(1)
    invCheck()
    print("Placing Block")
    turtle.placeDown()
    turtle.forward()
  else blockDown()
  end
end
 
function fill()
  if needsFuel() then
    refuel()
  else noblockDown()
 end
end
    while true do
	  fill()
    end

this works great, now I just need to find a way to get it to stop itself and add in a pause when it runs out of material.

Edit: Added in the pause for materials.