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

Turtle programming help

Started by Envy_x, 15 May 2013 - 06:46 PM
Envy_x #1
Posted 15 May 2013 - 08:46 PM
Hey guys I'm really not so good at this turtle coding business and wouldn't mind if someone could please fix my code up it would be much appreciated thanks.

Pastebin: http://pastebin.com/6Sq7eK8V

Spoiler–REFUEL–Slot 2 Is For Wood/Fuel
function refuel()
while turtle.getFuelLevel() == 0 do
turtle.selectSlot(2)
turtle.refuel(1)
end
end
–CHOP–Slot 2 Is Wood/Fuel
function chop()
turtle.selectSlot(2)
while turtle.comapare() == true do
turtle.dig()
turtle.digUp()
turtle.up()
else turtle.detectDown() == true
print("Can't Move Down)
else turtle.down()
end
end
end
end
–PLANT–Slot 1 Is For Saplings
function plant()
turtle.selectSlot(1)
turtle.place()
turtle.up()
end
–EMPTY
function empty()
turtle.select(3)
turtle.turnLeft()
turtle.turnLeft()
turtle.drop()
turtle.turnLeft()
turtle.turnLeft()
end
refuel()
plant()
chop()
sleep(2)
empty()
Apfeldstrudel #2
Posted 22 May 2013 - 01:35 PM

Put code in code windows and do your indentation right

What does the turtle do and what is not working
valithor #3
Posted 22 May 2013 - 03:42 PM
I believe that you are referring to the problem where you get error line 18 expected "end"
You cannot put a else in a while loop you will have to put a if loop where you put else

if turtle.detect==true do
  print("Can't Move Down")
else turtle.down()
end

That code ^^ will not mine the whole tree based on the way you wrote the code

To mine the whole tree you can use this

function chop()
   turtle.select(2)
   local x = 0
	  while turtle.compare()==true do
		 turtle.dig()
		 turtle.digUp()
		 turtle.up()
		 x = x+1
	  end
   for i = 1, x do
	 turtle.down()
   end
end

that should work i have not tested the code in game though so it might have a couple errors