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

Potato Farm Turtle

Started by Syntron, 28 December 2012 - 10:57 PM
Syntron #1
Posted 28 December 2012 - 11:57 PM
Hello guys i have a question. I wrote myself a program whitch lets my turtle farm my 9*9 field of potatos. It works just fine until my turtle ends the 2. cycle and starts acting odd. instead of turning right again it just keep up going straight forward. i dont know what ive done wrong. i checked the code for about 10000000000 times and didnt find the fault. Its proably a small one but i dont get it >.>

Spoiler

local a = 0
local side = 0
repeat
repeat
  turtle.select(1)
  turtle.digDown()
  turtle.placeDown()
  turtle.forward()
  side = side + 1
until side == 9

  if a % 2 == 1 then
   turtle.turnRight()
  else
   turtle.turnLeft()
  end
turtle.forward()
  if a % 2 == 1 then
   turtle.turnRight()
  else
   turtle.turnLeft()
  end
turtle.forward()
a = a + 1
until a == 9

i know theres proably a much easier way to do this^^ :P/>
Doyle3694 #2
Posted 29 December 2012 - 12:07 AM

   if a % 2 == 1 then
	  turtle.turnRight()
   else
	  turtle.turnLeft()
   end
	  turtle.forward()
   if a % 2 == 1 then
	  turtle.turnRight()
   else
	  turtle.turnLeft()
   end

would just be better like

   if a % 2 == 1 and a < 8 then
	  turtle.turnRight()
	  turtle.forward()
	  turtle.turnRight()
   elseif a % 2 == 1 and a < 8 then
	  turtle.turnLeft()
	  turtle.forward()
	  turtle.turnLeft()
   end
Doyle3694 #3
Posted 29 December 2012 - 12:15 AM
also, turtle.forward() should probably be first instead of last:

repeat
	  turtle.forward()
	  turtle.select(1)
	  turtle.digDown()
	  turtle.placeDown()
	  side = side + 1
   until side == 9
Though that wouldn't work perfect either. I would recommend just looking through you code and every step and everything that happens. Also, for loops. They are you friend.
Syntron #4
Posted 29 December 2012 - 01:05 AM
thanks for your help. :)/>
i think ill just rewrite the whole code and improve it^^
Syntron #5
Posted 29 December 2012 - 01:31 AM
yeah!! got it! used a lot of local functions but it works just fine :)/>
ivos97 #6
Posted 04 January 2013 - 09:31 AM
hello, looks great, i've been getting into computercraft for 2 weeks now, can you plz post the working program so i can use it, and learn from it:)

thanks:D
Loki #7
Posted 04 January 2013 - 11:08 AM
hello, looks great, i've been getting into computercraft for 2 weeks now, can you plz post the working program so i can use it, and learn from it:)

thanks:D
Try making your own? I know the forums is a place to learn and use other peoples work. But if you've been using computercraft for 2 weeks you should be able to accomplish something like this no problem. A potato farm was probably in my 10 first programs.
ChunLing #8
Posted 04 January 2013 - 02:47 PM
Look in the Programs and Turtle Programs forums for examples of (hopefully working) code that have been released by their authors for general use.