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

Problem with wheat farm

Started by Noobprogrammer, 02 October 2012 - 11:20 AM
Noobprogrammer #1
Posted 02 October 2012 - 01:20 PM
Hi guys,

I just started using ComputerCraft last week, and i tryed now to program my own wheat farm program, but It isn´t even starting.
I don´t know how many mistakes i got, but please help me, pros :(/>/>
Thanks for help!
Here what i tryed to do:


function Tanken()
benzin = turtle.getFuelLevel()
if benzin < 5 then
  turtle.select(16)
  turtle.refuel(1)
  turtle.select(1)
end

function Ernten()
turtle.digDown()
turtle.select(1)
turtle.placeDown()
end
function Auswerfen()
slot= 2
while slot < 16 do
turtle.select(slot)
turtle.dropDown()
slot = slot+1
end

länge = 10+0
breite =  8+0
c = länge+1
while breite > 0 do
  while länge > 0 do
    Tanken()
    Ernten()
    länge = länge-1
    turtle.forward()
  end
 
  breite = breite-1
  länge = 10+0
 
  Tanken()
  turtle.turnLeft()
  turtle.forward()
  turtle.turnLeft()
  turtle.forward()
 
  while länge > 0 do
    Tanken()
    Ernten()
    länge = länge-1
    turtle.forward()
  end
 
  breite = breite-1
  länge = 10
 
  Tanken()
  turtle.turnRight()
  turtle.forward()
  turtle.turnRight()
  turtle.forward()
end
Tanken()
turtle.turnRight()
while c > 0 do
  Tanken() 
  turte.forward()
  c = c-1
end
Tanken()
turtle.turnRight()
turtle.forward()
Auswerfen()
Tanken()
turtle.turnLeft()
turtle.turnLeft()
turtle.forward()
Tanken()
shell.run("reboot")
	
		 



Noob
Edited on 03 October 2012 - 11:28 AM
Mtdj2 #2
Posted 02 October 2012 - 01:27 PM
Well, you got one "end" too much (Line 15), also, where do you define b? (Line 45)
If it doesn't autorun, rename it to "startup" like so:

rename <filename> startup
I hope I helped.
Noobprogrammer #3
Posted 02 October 2012 - 01:45 PM
Thanks for the fast answer!
Ok, "b" must be "länge".
But it is still not working.
I updated my first post.
jag #4
Posted 02 October 2012 - 02:17 PM
Could you give the text some align, so it's easier to read?

Example:
if 1 < 2 then
print("1 is smaller then 2")
else
print("1 is not smaller then 2")
end
but instead you do
if 1 < 2 then
  print("1 is smaller then 2")
else
  print("1 is not smaller then 2")
end
Noobprogrammer #5
Posted 02 October 2012 - 02:47 PM
Ok, no problem!
LucasUK #6
Posted 02 October 2012 - 05:56 PM
is'nt indentation easier to read>? Im confused have I misunderstood something basic :S
Doyle3694 #7
Posted 02 October 2012 - 06:01 PM
Who said it is harder?
He asked for him to format his code to make it more readable.
LucasUK #8
Posted 02 October 2012 - 06:38 PM
looks like an extra end in function Ernten()
turtle.digDown()
turtle.select(1)
turtle.placeDown()
end
end
Noobprogrammer #9
Posted 03 October 2012 - 01:19 PM
ok i corrected
Noobprogrammer #10
Posted 03 October 2012 - 01:30 PM
I changed the ends.
When i try to run the program, I get that message:
bios 328, [string "weizen"] : 25 "=" expected
probably not the only wrong thing.
LucasUK #11
Posted 04 October 2012 - 01:25 AM
not at my pc to test and couldnt work out the error msg :S, but try this: (I mainly restructures your length width loop so try understand why, its lot simpler now, and addedd an end in Tanken, and Auserfen for the if and loop.


function Tanken()
benzin = turtle.getFuelLevel()
if benzin < 5 then
  turtle.select(16)
  turtle.refuel(1)
  turtle.select(1)
end
end

function Ernten()
turtle.digDown()
turtle.select(1)
turtle.placeDown()
end
function Auswerfen()
slot= 2
while slot < 16 do
turtle.select(slot)
turtle.dropDown()
slot = slot+1
end
end
länge = 10+0
breite =  8+0
c = länge+1
while breite > 0 do
  while länge > 0 do
	Tanken()
	Ernten()
	länge = länge-1
	turtle.forward()
  end

  breite = breite-1
  länge = 10+0

  Tanken()
  turtle.turnLeft()
  turtle.forward()
  turtle.turnLeft()
  turtle.forward()
  
end

Tanken()
turtle.turnRight()
while c > 0 do
  Tanken()
  turte.forward()
  c = c-1
end
Tanken()
turtle.turnRight()
turtle.forward()
Auswerfen()
Tanken()
turtle.turnLeft()
turtle.turnLeft()
turtle.forward()
Tanken()
shell.run("reboot")