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

[Lua] I'm having trouble with some code, please help.

Started by popdog15, 11 April 2012 - 10:52 AM
popdog15 #1
Posted 11 April 2012 - 12:53 PM
Here is the code -


function lumberjack()
   x = 0

	while turtle.detect() do
	   turtle.dig()
	   turtle.up()	
	turtle.digUp()
	x = x+1
	end
  

while turtle.detectDown() == false do
		turtle.down()
  
end

	print ("The tree was "..x.." in height of blocks.")
end
function objectfinder
  if turtle.detect() then
   popapi.lumberjack()
  end
  turtle.turnRight()
  turtle.forward()
  turtle.turnLeft()
  turtle.fordward()
  os.sleep(0.1)
  turtle.back()
  turtle.turnLeft()
  turtle.forward()
  turtle.forward()
  turtle.turnRight()
  turtle.forward()
  os.sleep(0.1)
end

and I'm having trouble with objectfinder() because what I want it to do is "popapi.lumberjack()" whenever it detects a block when the function is running, but it just looks at the block, and keeps on going…
I've been trying to figure this out for 2 days ._.

Oh yeah- it actually is function objectfinder() not just function objectfinder :P/>/> I'm not that stupid/new.
Still, not working….
OmegaVest #2
Posted 11 April 2012 - 03:36 PM
Hmm. Well, the only thing I see right now is that you are calling this api to run it. I don't think that is necessary, and may actually be hindering you.
Unless you are using another api, in which case it could be that is having a problem.
Luanub #3
Posted 11 April 2012 - 06:25 PM
Since the lumberjack function is in this script and not part of another api you do not need the popapi in front of it, you can call just lumberjack()
popdog15 #4
Posted 11 April 2012 - 09:39 PM
Since the lumberjack function is in this script and not part of another api you do not need the popapi in front of it, you can call just lumberjack()
Hmm. Well, the only thing I see right now is that you are calling this api to run it. I don't think that is necessary, and may actually be hindering you.
Unless you are using another api, in which case it could be that is having a problem.

Thanks, I'll try that out! (I'm semi-new to coding/lua :P/>/> )