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

Wheat farming and replanting program not working

Started by Bappleinator, 19 June 2013 - 05:06 PM
Bappleinator #1
Posted 19 June 2013 - 07:06 PM
Hello,I tried programming a program for a farming turtle to farm and replant my wheat.the problwm is,when i start the program,nothing happens.
There i no error or something,it simply doesn't happen anything.Here is the code:


function line1()
for i=1,7 do
turtle.dig()
turtle.forward()
turtle.placeDown(1)
end
end
function turn1()
turtle.turnRight()
turtle.forward()
turtle.dig()
turtle.forward()
turtle.placeDown(1)
turtle.turnRight()
end
function line2()
for i2=1,6 do
turtle.dig()
turtle.forward()
turtle.placeDown(1)
end
end

function turn2()
turtle.turnLeft()
turtle.dig()
turtle.forward()
turtle.placeDown(1)
turtle.turnLeft()
end
function line3()
for i3=1,6 do
turtle.dig()
turtle.forward()
turtle.placeDown(1)
end
end
function turn3()
turtle.turnRight()
turtle.forward()
turtle.dig()
turtle.forward()
turtle.placeDown(1)
turtle.turnRight()
end
function line4()
for i4=1,6 do
turtle.dig()
turtle.forward()
turtle.placeDown(1)
end
end
function final()
turtle.forward()
turtle.turnRight()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.drop(2)
turtle.turnRight()
end
Edited by
Lyqyd #2
Posted 19 June 2013 - 11:19 PM
Split into new topic.

Try calling one or more of the functions you've declared.
apemanzilla #3
Posted 20 June 2013 - 07:18 AM
In that program all you're doing is declaring the function; you need to actually call it. Try adding "line1()" to the end to run the function you have there.
Bappleinator #4
Posted 20 June 2013 - 10:18 AM
In that program all you're doing is declaring the function; you need to actually call it. Try adding "line1()" to the end to run the function you have there.
Thank you,it worked!I actually didn't even know what functions do when i used them(this is the second program i make)and didn't know about them.
I also wrote a knew,shorter and actually working code now(the other one couldn't plant seeds because the turtle was directly on the tilled dirt).
This is the working one:
Spoiler

function line1()
for i=1,7 do
turtle.forward()
turtle.digDown()
turtle.select(1)
turtle.placeDown()
end
end
function turn1()
turtle.turnRight()
turtle.forward()
turtle.forward()
turtle.turnRight()
turtle.digDown()
turtle.placeDown()
end
function line2()
for i2=1,6 do
turtle.forward()
turtle.digDown()
turtle.select(1)
turtle.placeDown()
end
end
function turn2()
turtle.turnLeft()
turtle.forward()
turtle.turnLeft()
turtle.digDown()
turtle.placeDown()
end
function final()
turtle.forward()
turtle.turnRight()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.select(2)
turtle.drop()
turtle.turnRight()
turtle.select(1)
end
line1()
turn1()
line2()
turn2()
line2()
turn1()
line2()
final()
apemanzilla #5
Posted 20 June 2013 - 12:01 PM
In that program all you're doing is declaring the function; you need to actually call it. Try adding "line1()" to the end to run the function you have there.
Thank you,it worked!I actually didn't even know what functions do when i used them(this is the second program i make)and didn't know about them.
I also wrote a knew,shorter and actually working code now(the other one couldn't plant seeds because the turtle was directly on the tilled dirt).
This is the working one:
Spoiler

function line1()
for i=1,7 do
turtle.forward()
turtle.digDown()
turtle.select(1)
turtle.placeDown()
end
end
function turn1()
turtle.turnRight()
turtle.forward()
turtle.forward()
turtle.turnRight()
turtle.digDown()
turtle.placeDown()
end
function line2()
for i2=1,6 do
turtle.forward()
turtle.digDown()
turtle.select(1)
turtle.placeDown()
end
end
function turn2()
turtle.turnLeft()
turtle.forward()
turtle.turnLeft()
turtle.digDown()
turtle.placeDown()
end
function final()
turtle.forward()
turtle.turnRight()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.select(2)
turtle.drop()
turtle.turnRight()
turtle.select(1)
end
line1()
turn1()
line2()
turn2()
line2()
turn1()
line2()
final()
Functions basically just compress a bunch of lines of code into one, useful for repeating the same thing several times like this.
dent308 #6
Posted 20 June 2013 - 12:48 PM
Another thing you may want is to check your fuel levels and refuel if needed.


function showfuel()
  local f = turtle.getFuelLevel()
  if f < 1 then
	print("OUT OF FUEL")
	turtle.refuel(1)
  else
	print("I HAS : ".. f .." fuel")
  end
end