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

Sugar Cane Farm

Started by TheGreekMan2, 01 June 2014 - 04:29 PM
TheGreekMan2 #1
Posted 01 June 2014 - 06:29 PM
I understand there are way better versions of this, but i like to program on my own. This program was working fine when i just had it farm R3 (top row of sugar cane)
then when i added returning to start row 2, refueling, and depositing items the turtle spins. Any help is appreciated :)/>


local function BreakSugarCane()
  turtle.dig()
  turtle.forward()
end

local function NextRowR()
turtle.turnRight()
turtle.forward()
turtle.forward()
turtle.turnRight()
end

local function NextRowL()
turtle.turnLeft()
turtle.forward()
turtle.forward()
turtle.turnLeft()
end

local function BreakRow()
  for i = 1,14 do
  BreakSugarCane()
end
end

local function Break2Row()
BreakRow()
NextRowR()
BreakRow()
NextRowL()
end

local function FarmSugarCaneR3()
  for i = 1, 2 do
	turtle.up()
  end

  for i=1 ,3 do
	Break2Row()
  end
end

local function FarmSugarCaneR2()
  turtle.up()
  for i=1, 3 do
	Break2Row()
  end
end

local function ReturnToStartR3()
turtle.turnLeft()
for i=1,12 do
  turtle.forward()
end
turtle.down()
turtle.down()
turtle.turnRight()
end

local function ReturnToStartR2()
turtle.turnLeft()
for i=1,12 do
turtle.forward()
end
turtle.down()
turtle.turnRIght()
end

local function FarmingSC()
  FarmSugarCaneR3()
  ReturnToStartR3()  
  FarmSugarCaneR2()
  ReturnToStartR2()
end

  term.setCursorPos(1,1)
  term.write("Place fuel in slot 1")
  sleep(2)
  term.clear()
  turtle.select(1)
  turtle.refuel()
  sleep(5)
  FarmingSC()
  turtle.turnRight()
  turtle.turnRight()
  turtle.drop()
  turtle.turnLeft()
  turtle.turnLeft()

Edited by
Whitecatblack #2
Posted 01 June 2014 - 11:10 PM
TheGreekMan2 said:
Any help is appreciated :)/>
Alright so first let me do this to minimize the amount of extra space I take up:
Spoiler

local function BreakSugarCane()
  turtle.dig()
  turtle.forward()
end

local function NextRowR()
turtle.turnRight()
turtle.forward()
turtle.forward()
turtle.turnRight()
end

local function NextRowL()
turtle.turnLeft()
turtle.forward()
turtle.forward()
turtle.turnLeft()
end

local function BreakRow()
  for i = 1,14 do
  BreakSugarCane()
end
end

local function Break2Row()
BreakRow()
NextRowR()
BreakRow()
NextRowL()
end

local function FarmSugarCaneR3()
  for i = 1, 2 do
		turtle.up()
  end

  for i=1 ,3 do
		Break2Row()
  end
end

local function FarmSugarCaneR2()
  turtle.up()
  for i=1, 3 do
		Break2Row()
  end
end

local function ReturnToStartR3()
turtle.turnLeft()
for i=1,12 do
  turtle.forward()
end
turtle.down()
turtle.down()
turtle.turnRight()
end

local function ReturnToStartR2()
turtle.turnLeft()
for i=1,12 do
turtle.forward()
end
turtle.down()
turtle.turnRIght()
end

local function FarmingSC()
  FarmSugarCaneR3()
  ReturnToStartR3()  
  FarmSugarCaneR2()
  ReturnToStartR2()
end

>term.clear here<
  term.setCursorPos(1,1)
  term.write("Place fuel in slot 1")
  sleep(2)
  term.clear()
>term.setCursorPos here<
  turtle.select(1)
  turtle.refuel()
  sleep(5)
  FarmingSC()
  turtle.turnRight()
  turtle.turnRight()
  turtle.drop()
  turtle.turnLeft()
  turtle.turnLeft()]

So first things first, I noticed in line 66 you have turtle.turnRIght() instead of turtle.turnRight(). Remember, functions are case sensitive, so be careful with that.

Next, I just ran your program on a test turtle, albeit I didn't have any sugarcane set up, and it seemed to run fine. So if fixing what I said above doesn't help, please help me replicate the error.

And I know you don't want to use other people's code, that you'd rather do it yourself, but let me add 2 quick lines to make things just look a little better without messing with any of the code:

term.clear()

term.setCursorPos(1,1)
Put these two lines of code where I marked on your code above, and it will just have things looking clean on the turtle's screen when he is done his task.

Whitecatblack
Edited on 01 June 2014 - 09:11 PM
BlockSmith #3
Posted 03 June 2014 - 12:47 AM
How much fuel are you filling your turtle with? It sounds like you could be running out mid-program. To avoid you could either add more fuel at the start, program a refuel function, or you could add "turtle.digDown()" to your BreakSugarCane function and completely remove the need for your FarmSugarCaneR2() and ReturnToStartR2() functions entirely.