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

Farm

Started by grand_mind1, 23 December 2012 - 11:10 AM
grand_mind1 #1
Posted 23 December 2012 - 12:10 PM
I am trying to make a simple turtle farm that just places down seeds, uses bonemeal, and picks it up until it has enough wheat.

wheat = turtle.getItemCount(3) -- where wheat is kept
bone = turtle.getItemCount(2) -- this is where the bonemeal is kept until it runs out and the last wheat comes in
both = wheat + bone
function drop()
  turtle.turnLeft()
  turtle.select(3)
  turtle.drop()
  turtle.select(1)
  turtle.turnRight()
  print("I'm done!")
  sleep(10)
  os.reboot()
end
function farm()
  while wheat ~= 32 do
	turtle.select(1)
	turtle.place()
	turtle.select(2)
	turtle.place()
	turtle.dig()
    wheat = turtle.getItemCount(3)
	if both == 32 then
	  if turtle.compareTo(13) then --compares wheat to wheat in slot 13
		turtle.select(2) -- select the wheat that is in the wrong spot
		turtle.transferTo(3)
		drop()	
	  end
	end
  end
end
if bone == 0 then
  print("Gotta get some bonemeal!")
  turtle.turnLeft()
  turtle.turnLeft()
  turtle.suck(2)
  turtle.turnLeft()
  turtle.turnLeft()
  farm()
else
  farm()
end
My first problem was that when it used the last bonemeal it would put the wheat in the wrong spot and it would not drop because it would never have 32 wheat. To fix this I just said that if the place where the wheat is supposed to be and the slot where it is not supposed to be add up to 32 then put them in the same slot and put them in the chest. This works, but only when it doesn't have to get bonemeal. If it has to turn around and get bonemeal then it won't drop the wheat. Anyone know why it does this?
Help is appreciated!
Thanks! :D/>
ChunLing #2
Posted 23 December 2012 - 05:13 PM
It seems like you're giving excessively tight demands to how to make the program run. Which is odd, because you can only farm 32 wheat at a time with this.

To fix the problem with picking up stuff in your empty bonemeal slot, check if the slot is empty immediately after placing from that slot, before digging.

Before messing about with dumping things in a chest, use up your entire turtle inventory. You should have 896 wheat before you start using a chest.

After the beginning of your program, where you set the values of wheat, bone, and both, you never update bone or both. They remain the same for the rest of the program. If you had bone at the beginning, then bone never == 0, and if it did, then bone would always == 0 even after you get more bone.