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

Help with Turtle Shearing

Started by Greenslycer, 12 January 2014 - 01:15 PM
Greenslycer #1
Posted 12 January 2014 - 02:15 PM
Could you help with this program to shear turtles?

while turtle.getItemCount(1) == 1 do
turtle.place()
turtle.select(2)
turtle.dropDown()
turtle.select(1)
sleep(60)
turtle.turnRight()
turtle.select(1)
turtle.suckUp()
if turtle.getItemCount(1) == 0 then
turtle.select(1)
turtle.suckUp()
end
It has a while loop which uses a pair of shears in the first slot. I tried to put an if statement inside the loop which gets shears from the chest above it if there are no items in slot 1.
It dumps wool in the second slot into a chest below.
CometWolf #2
Posted 12 January 2014 - 03:53 PM
Im assuming you're posting here because you're getting an error. Please post the error next time. You're missing an end to close your while loop.
Greenslycer #3
Posted 12 January 2014 - 04:06 PM
I have changed the code slightly so it closes the while statement and added an if statement which tries to suck from the inventory above it if there is nothing in slot 1, but it is not taking any items from the inventory above when the shears break.


while turtle.getItemCount(1) == 1 do
turtle.place()
turtle.select(2)
turtle.dropDown()
turtle.select(1)
sleep(60)
turtle.turnRight()
turtle.select(1)
turtle.suckUp()
end
if turtle.getItemCount(1) == 0 then
turtle.select(1)
turtle.suckUp()
end
CometWolf #4
Posted 12 January 2014 - 04:18 PM
Since you put the if statement outside your while loop, the loop will stop, then he'll suck up the new shears, then the program ends.
Try this instead

while true do --never ending loop
  turtle.place()
  turtle.select(2)
  turtle.dropDown()
  turtle.select(1)
  sleep(60)
  turtle.turnRight()
  turtle.select(1)
  turtle.suckUp()
  while turtle.getItemCount(1) == 0 do --repeats this until there's an item in slot 1
    turtle.select(1)
    turtle.suckUp()
  end -- then resumes the original loop
end