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

Logic error in farm construction program?

Started by giraffenlp, 31 May 2013 - 11:56 AM
giraffenlp #1
Posted 31 May 2013 - 01:56 PM
hello i´m new to this Forum and i´m not so good in writing English but i hope u can Understand me.

I was writing a turtle program and it seems to work but there is one bug that i cant find

The program should build a farm terrain for an automatic farm

here is my code

shell.run("clear")
local Num1,Num2,Num3,Num4,Num6,Num7 = 1,2,3,4,5,6,7
  print("Herzlich Willkommen zum Felder Generator\n")
  print("Wie viele Felder sollen nebeneinander gebaut werden?:")
  local felder = read()
  term.setCursorPos(1,7)
  print("Wie viele Felderreihen sollen gebaut werden?:")
  local reihen = read()
  term.setCursorPos(1,9)
  print("Berechne Erde\n")
  erde = ((felder*7)*6)*reihen
  print("Es werden ")
  print (erde)
  print(" Erd Blöcke gebraucht das sind ")
  erde = erde/64
  print (erde)
  print("Stacks\n")
  print ("Bitte fülle den Turtle mit Kohle und Erde.\n")
  print ("Kohle auf Platz eins und erde auf 2-16.\n")
   print("Wenn alles aufgefüllt ist Tippe Y zum Start ein:")
   input = read()
	 if input == "Y" then
    turtle.select(1)
    turtle.refuel()
    turtle.select(2)
    selecteditemslot = 2
    itemcount = turtle.getItemCount(selecteditemslot)
   b=Num7
    c=7
    d = (reihen*1)
    while d>0 do
    while c >0 do
	 a = (felder*6) + felder
	  while a >0 do
	  turtle.forward()
	  a=a-1
	   if turtle.detectDown() then
		   turtle.digDown()
	   end
	    if itemcount > 0 then
		 turtle.placeDown()
		 itemcount = itemcount-1
	    else
	    selecteditemslot=selecteditemslot+1
		 turtle.select(selecteditemslot)
		 itemcount = turtle.getItemCount(selecteditemslot)
		 turtle.placeDown()
		 itemcount = itemcount-1
	    end
	   end
					 if b==Num7 then
		 b=Num6
		 turtle.turnLeft()
		 turtle.forward()
		 turtle.turnLeft()
		  if itemcount > 0 then
		   turtle.placeDown()
		   itemcount = itemcount-1
		  else
		   selecteditemslot=selecteditemslot+1
		   turtle.select(selecteditemslot)
		   itemcount = turtle.getItemCount(selecteditemslot)
		   turtle.placeDown()
		   itemcount = itemcount-1
		  end
			   elseif b==Num6 then
					    b=Num5
		 turtle.turnRight()
		 turtle.forward()
		 turtle.turnRight()
		  if itemcount > 0 then
		   turtle.placeDown()
		   itemcount = itemcount-1
		  else
		   selecteditemslot=selecteditemslot+1
		   turtle.select(selecteditemslot)
		  itemcount = turtle.getItemCount(selecteditemslot)
		   turtle.placeDown()
		   itemcount = itemcount-1
		  end
					   elseif b==Num5 then
					    b=Num4
		 turtle.turnLeft()
		 turtle.forward()
		 turtle.turnLeft()
		  if itemcount > 0 then
		   turtle.placeDown()
		   itemcount = itemcount-1
		  else
		   selecteditemslot=selecteditemslot+1
		   turtle.select(selecteditemslot)
		   itemcount = turtle.getItemCount(selecteditemslot)
		   turtle.placeDown()
		   itemcount = itemcount-1
		  end
						 elseif b==Num4 then
						 b=Num3
		 turtle.turnRight()
		 turtle.forward()
		 turtle.turnRight()
		  if itemcount > 0 then
		   turtle.placeDown()
		   itemcount = itemcount-1
		  else
		   selecteditemslot=selecteditemslot+1
		   turtle.select(selecteditemslot)
		  itemcount = turtle.getItemCount(selecteditemslot)
		   turtle.placeDown()
		   itemcount = itemcount-1
		  end
					  elseif b==Num3 then
					  b=Num2
		 turtle.turnLeft()
		 turtle.forward()
		 turtle.turnLeft()
		  if itemcount > 0 then
		   turtle.placeDown()
		   itemcount = itemcount-1
		  else
		   selecteditemslot=selecteditemslot+1
		   turtle.select(selecteditemslot)
		   itemcount = turtle.getItemCount(selecteditemslot)
		   turtle.placeDown()
		   itemcount = itemcount-1
		  end
						 elseif b==Num2 then
						 b=Num1
	    turtle.turnRight()
		 turtle.forward()
		 turtle.turnRight()
		  if itemcount > 0 then
		   turtle.placeDown()
		   itemcount = itemcount-1
		  else
		   selecteditemslot=selecteditemslot+1
		   turtle.select(selecteditemslot)
		  itemcount = turtle.getItemCount(selecteditemslot)
		   turtle.placeDown()
		   itemcount = itemcount-1
		  end
					  elseif b==Num1 then
					   b=Num7
		 turtle.turnLeft()
		 turtle.forward()
		 turtle.turnLeft()
						    turtle.down()
							 e=(felder*6) + felder
							    while e>0 do
								 turtle.forward()
								    e=e-1
							    end
							    turtle.turnLeft()
							    turtle.turnLeft()
		  if itemcount > 0 then
		   turtle.placeDown()
		   itemcount = itemcount-1
		  else
		   selecteditemslot=selecteditemslot+1
		   turtle.select(selecteditemslot)
		   itemcount = turtle.getItemCount(selecteditemslot)
		   turtle.placeDown()
		   itemcount = itemcount-1
		  end
							    else
								 print("neues feld")
	    end 
	   c=c-1
	  end
	 end
		    c=7
		    d=d-1
		   
	    end

when i was using it it build the first layer and go down to build the second but then it stops and i can´t find the problem please help me
Lyqyd #2
Posted 31 May 2013 - 11:19 PM
Split into new topic. A title was provided for you.
Bomb Bloke #3
Posted 01 June 2013 - 12:41 AM
							    else
								 print("neues feld")
	    end 
	   c=c-1
	  end
	 end
		    c=7
		    d=d-1
		   
	    end

Should instead be:

							    else
								 print("neues feld")
	    end 
	   c=c-1
	  end
		    c=7
		    d=d-1
		   end
	    end

This'd be clear to you if you indented your code better. ;)/>
giraffenlp #4
Posted 01 June 2013 - 06:47 AM
Okay thanks for that i will try it later that day