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

Why does this not work?

Started by NoobAce, 01 September 2013 - 04:52 PM
NoobAce #1
Posted 01 September 2013 - 06:52 PM
Hey! Im new here and i wanted to try this mod so i use mindcrack for it.. Well to my problem now!


function place()
  turtle.place()
  turtle.place()
  turtle.place()
  turtle.place()
  turtle.place()
  turtle.place()
  turtle.place()
end

function bmeal()
  turtle.select(1)
  while
	turtle.compare() == true
	  do
		turtle.select(2)
		place()
  end
end

function plant()
  print("Planting yo..")
  turtle.select(1)
  turtle.place()
end

function rr()
  turtle.turnRight()
  turtle.turnRight()
end

function dirt()
  turtle.select(5)
  while
	turtle.compareDown() == false
	  do
		turtle.forward()
  end
  print("Found dirt!")
  rr()
  turtle.forward()
  rr()
end	

function fuel()
  turtle.select(3)
  print("Checking fuel..")
  if
	turtle.getFuelLevel() < 300
	  then
		print("Refueling yo")
		turtle.refuel()
		  else
			print("I haz dem fuel.")
  end
end

function chop()
  turtle.select(4)
  while
	turtle.detect()
	  do
		turtle.dig()
		turtle.digUp()
		turtle.up()
  end
  turtle.select(16)
  while
	turtle.detectDown() == false
	  do
		turtle.down()
  end
end

function bchop()
  if
	bmeal()
	  then
		chop()
  end
end
while
  (dirt() or plant())
	do
	  bchop()
end

slot 1 saplings
slot 2 bonemeal
slot 3 fuel
slot 4 log
slot 5 dirt
You probably already know it lol

I have made this and im really new to coding at any language so i have no idea what am i doing basically..
When i run this it stops after the planting part and ends..
Lyqyd #2
Posted 01 September 2013 - 06:57 PM
Split into new topic.

You don't return anything from the dirt or plant functions, which means they're returning nil. In your while loop at the end, it evaluates the results of `dirt() or plant()`, both of which return nil, which means that the expression evaluates to false, so bchop() will never execute, the loop ends, and since that's the last part of the program, it ends too.
NoobAce #3
Posted 01 September 2013 - 07:00 PM
Wow that was a really quick reply .-. ..
Hmm what do you mean dont return anything?
Lyqyd #4
Posted 01 September 2013 - 07:03 PM
Check out the lua-users wiki functions tutorial, specifically the Function return values section.
NoobAce #5
Posted 01 September 2013 - 07:05 PM
Alright thank you!