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

My farming Turtle help!

Started by DerDuden, 10 April 2013 - 06:54 AM
DerDuden #1
Posted 10 April 2013 - 08:54 AM
Hi everyone,

so yesterday i wrote a program for my farming Turtle and it looks something like this:

turtle.select(1)
turtle.digDown()
turtle.placeDown()

while turtle.forward() do

turtle.digDown()
turtle.placeDown()
end

turtle.turnRight()
turtle.forward()
turtle.turnRight()
turtle.digDown()
turtle.placeDown()

while turtle.forward() do

turtle.digDown()
turtle.placeDown()
end

turtle.turnLeft()
turtle.forward()
turtle.turnLeft()
turtle.digDown()
turtle.placeDown()

The Turtle starts by digging down and by placing a seed from slot 1. It then continues to go forward and breaking the wheat and then placing the seeds.

I have a 2 block high fence so if the turtle runs into it it stops and turns.

Now my question is, what do i do if the turtle runs out of seeds in the first slot?
and should I use Functioons and how do i use them?

And sorry for the dumb question but i am pretty new to Computercraft =)

Mfg Duden
Berge #2
Posted 10 April 2013 - 09:15 AM

local function checkSeed()
  if turtle.getItemCount() < 2 then
	for i=1,16 do
	  turtle.select(i)
	  if turtle.compare(1) then
		if turtle.getItemCount(i) > 0  then
		  break
		end
	  end
	end
  end
end
I can't test this atm but place this at the top of your code, then put
 checkSeed() 
above any
turtle.placeDown() 
If it doesnt work just let me know then ill go in-game and try something else. Just make sure thres at least one seed in slot 1
I can't seem to get the spacing to work correctly but ohh well.
Edited on 10 April 2013 - 07:21 AM
Noiro #3
Posted 10 April 2013 - 09:47 AM
Berge, it gets the item count and then what? Also OP, I'd suggest using functions to speed up your coding. For example:

function farm()
  turtle.digDown()
  if turtle.getItemCount(1)>1 then
	turtle.placeDown()
  else
	refill()
  end

end
function refill()
  for i=2, 16 do
	turtle.select(i)
if turtle.compare(1) then
   turtle.transferTo(1)
end
  end
end
function wait()
  print("Please insert more fuel into the turtle's slots.")
  while getItemcount(1)<2
	refill()
sleep(.5)
  end
end

With this, you wouldn't use the placedown or dig. You would just use farm() instead. This will include that and also check to be sure he has all the seeds he needs. If he doesn't, he will sit there until you put some in him (doesn't matter inv slot you put them in).
DerDuden #4
Posted 10 April 2013 - 10:25 AM
Yeah thanks singify it worked great!

Mfg Duden =)