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

I need help with my Melon Farming Turtle

Started by iMineing, 19 July 2012 - 08:43 PM
iMineing #1
Posted 19 July 2012 - 10:43 PM
Alright so I am pretty new at lua but I think I got the jist of it down, so I attempted making a auto harvest miner. What I did was have melons set up in a 5x2 row with the mining turtle on the row with the melons. What would happen is he would go down the row with melons and if he detected a melon below him he would stop, dig the melon, harvest it, and move on the row, and at the end of the row would be a block that he turns on and goes over the stems back to his original position, only to loop again for an infinite time. But for some reason I cant figure out he doesn't wanna stop and he keeps going forward, here's the code for the melon farmer.




 Y = 1

while Y == 1 do
turtle.forward()
end

while turtle.detectDown() do
Y=0
turtle.digDown()
turtle.down()
turtle.up()
Y=1
end

while turtle.detect() do
Y=0
turtle.turnLeft()
turtle.forward()
turtle.turnLeft()
Y=1
end

Anybody know what the problem is?
MysticT #2
Posted 19 July 2012 - 11:20 PM
Read carefully your code, and try to understand it.

Y = 1

while Y == 1 do
  turtle.forward()
end

while turtle.detectDown() do
  Y=0
  turtle.digDown()
  turtle.down()
  turtle.up()
  Y=1
end

while turtle.detect() do
  Y=0
  turtle.turnLeft()
  turtle.forward()
  turtle.turnLeft()
  Y=1
end
When will each loop stop?