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

Auto tilling program, runs with no errors, but doesn't work.

Started by _LukeIsHere_, 18 June 2016 - 05:56 PM
_LukeIsHere_ #1
Posted 18 June 2016 - 07:56 PM
I made a code earlier to try to make an autohoe turtle. Assume that the turtle, when the program is ran, has a hoe in its left hand, and a pickaxe its in the selected slot. When I run, it gives no errors, it just doesnt work.

local t = 0
local i = 0
repeat
    i=i+1
    turtle.forward()
    turtle.digDown()
    if turtle.detect() then
	    if t==0 then
		    t=1
		    turtle.turnLeft()
		    turtle.equipLeft()
		    turtle.dig()
		    turtle.forward()
		    turtle.equipLeft()
		    turtle.digDown()
		    turtle.turnLeft()
		    turtle.equipLeft()
		    turtle.dig()
		    turtle.equipLeft()
		    turtle.digDown()
	    end
	    if t==1 then
		    t=0
		    turtle.turnRight()
		    turtle.forward()
		    turtle.digDown()
		    turtle.turnRight()
	    end
    end
until i==32
valithor #2
Posted 18 June 2016 - 10:19 PM
Does the turtle have fuel? If it doesn't then it will not be able to move, and if there isn't a block under it, or in front of it, it will appear to do nothing.

Things you can do to improve the script, but are not required to get it to work:

If you did not know this, a turtle can actually carry 2 tools on it at a time. You could actually have both a pick and a hoe equipped at the same time if you wanted to.

Also, you can use a repeat loop like how you are using it, but you could also use a for loop to do what you are wanting.

Example assuming you equip a pick on one side and a hoe on the other:

local t = 0
for i = 1, 32 do --# i will increase by 1 with every iteration of the loop automatically
	turtle.forward()
	turtle.digDown()
	if turtle.detect() then
			if t==0 then
					t=1
					turtle.turnLeft()
					turtle.dig()
					turtle.forward()
					turtle.digDown()
					turtle.turnLeft()
					turtle.dig()
					turtle.digDown()
            elseif t==1 then
					t=0
					turtle.turnRight()
					turtle.forward()
					turtle.digDown()
					turtle.turnRight()
			end
	end
end

edit:

Didn't notice this the first time i skimmed through the code, but you would also want to use a elseif instead of a if when checking if t==1. As it is, the first if statement will run if t == 0 and in that block it changes t to equal 1, so both if statement would run everytime, which is probably not what you are wanting to happen. I modified the example code to show this change.
Edited on 18 June 2016 - 08:41 PM
_LukeIsHere_ #3
Posted 18 June 2016 - 10:25 PM
Does the turtle have fuel? If it doesn't then it will not be able to move, and if there isn't a block under it, or in front of it, it will appear to do nothing.

Things you can do to improve the script, but are not required to get it to work:

If you did not know this, a turtle can actually carry 2 tools on it at a time. You could actually have both a pick and a hoe equipped at the same time if you wanted to.

Also, you can use a repeat loop like how you are using it, but you could also use a for loop to do what you are wanting.

Example assuming you equip a pick on one side and a hoe on the other:

local t = 0
for i = 1, 32 do --# i will increase by 1 with every iteration of the loop automatically
	turtle.forward()
	turtle.digDown()
	if turtle.detect() then
			if t==0 then
					t=1
					turtle.turnLeft()
					turtle.dig()
					turtle.forward()
					turtle.digDown()
					turtle.turnLeft()
					turtle.dig()
					turtle.digDown()
			end
			if t==1 then
					t=0
					turtle.turnRight()
					turtle.forward()
					turtle.digDown()
					turtle.turnRight()
			end
	end
end

Oh wow, dumbest mistake ever. Forgot to fuel it hahahaha.

My only issue with that however, is that the grass under the turtle gets digged, not hoed
valithor #4
Posted 18 June 2016 - 11:03 PM
Does the turtle have fuel? If it doesn't then it will not be able to move, and if there isn't a block under it, or in front of it, it will appear to do nothing.

Things you can do to improve the script, but are not required to get it to work:

If you did not know this, a turtle can actually carry 2 tools on it at a time. You could actually have both a pick and a hoe equipped at the same time if you wanted to.

Also, you can use a repeat loop like how you are using it, but you could also use a for loop to do what you are wanting.

Example assuming you equip a pick on one side and a hoe on the other:

local t = 0
for i = 1, 32 do --# i will increase by 1 with every iteration of the loop automatically
	turtle.forward()
	turtle.digDown()
	if turtle.detect() then
			if t==0 then
					t=1
					turtle.turnLeft()
					turtle.dig()
					turtle.forward()
					turtle.digDown()
					turtle.turnLeft()
					turtle.dig()
					turtle.digDown()
			end
			if t==1 then
					t=0
					turtle.turnRight()
					turtle.forward()
					turtle.digDown()
					turtle.turnRight()
			end
	end
end

Oh wow, dumbest mistake ever. Forgot to fuel it hahahaha.

My only issue with that however, is that the grass under the turtle gets digged, not hoed

I am assuming you meant tall grass (you need a block between the turtle and the ground to hoe the ground under it anyway). You could just call digDown twice, once would break any block under it, and the second time would hoe the block under it.
Bomb Bloke #5
Posted 19 June 2016 - 04:15 AM
Also remember that the turtle must hover a block above the ground beneath it in order to use the hoe. If it's directly above the ground then it can't till the land.