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

[Question] reset program for turtle farming

Started by Falk358, 24 July 2012 - 02:15 PM
Falk358 #1
Posted 24 July 2012 - 04:15 PM
Hello everybody!

Im pretty new to coding and cc, so this might be nooby. Still, I whant to ask you guys what I could do about my reset program.

The first file called pumpkinfarm is a program to (you guessed it) farm pumpkins on 3 places. The turtle moves between three spaces and checks if there are pumkins in front of it and harvests them.
Easy. But since after rellogging in I would have to bring the turtles manually back into position I decided to write a program to reset them, so its called "reset".
Here comes the tricky bit. I let the turtle check its position by making it turn right until it detects with turtle.detect the fence behind it. Now we know which direction its facing.
I let it go right and forward until it detects a fence underneath it. This is the starting block. So I turn it toward the fence and let it turn left ( or right) 2 times. Now its successfully reseted.
The problem is that if the turtle stands on the starting block and faces the wrong direction, it goes totally wrong of course. Does anybody know how I could fix this?

pumkinfarm:
x = 1
while x == 1
do
local i = 1
repeat
if turtle.detect() == true
then turtle.dig()
turtle.turnLeft()
turtle.forward()
turtle.turnRight()

else turtle.turnLeft()
turtle.forward()
turtle.turnRight()
end
i = i + 1
until i == 3
local c = 1
repeat
if turtle.detect() == true
then turtle.dig()
turtle.turnRight()
turtle.forward()
turtle.turnLeft()

else turtle.turnRight()
turtle.forward()
turtle.turnLeft()

end
c = c + 1
until c == 3
end

reset:
if turtle.compareDown() == true
then
while turtle.compare() == false
do turtle.turnRight()
end
turtle.turnLeft()
turtle.turnLeft()
end
while turtle.compare() == false
do turtle.turnRight()
end
turtle.turnLeft()
turtle.forward()

if turtle.compareDown() == false
then turtle.forward()
else while turtle.compare() == false
do turtle.turnRight()
end
end
turtle.turnLeft()
turtle.turnLeft()

http://
these are the turtles in reseted position. They both have a fence in their 1. slot for turtle.compare()
skore13 #2
Posted 24 July 2012 - 08:02 PM
You can use GPS.
Falk358 #3
Posted 24 July 2012 - 11:11 PM
I already considered that. BUt i thought you could only use it to locate sth? How (roughly) would a script look like that moves a turtle to certain coords?
Falk358 #4
Posted 25 July 2012 - 08:45 AM
Ok i solved the problem. Someone delete thread psl.
Lyqyd #5
Posted 25 July 2012 - 03:32 PM
Ok i solved the problem. Someone delete thread psl.

It's better to post your solution so that other people with similar issues might be able to find the solution without having to make their own topic.
Falk358 #6
Posted 25 July 2012 - 08:15 PM
I know that the program reset as it is like posted only works when im not on the starting block. So i made two functions. One is as above, the other is like this:

function start ()
while turtle.detect() == false do
turtle.turnRight()
end
turtle.turnLeft()
turtle.turnLeft()
end

then i used the two functions in an if statement:
if turtle.compareDown() == true then
start()
else notstart() … is the other function
end
Falk358 #7
Posted 26 July 2012 - 10:07 AM
omg in the end it was still bugged. I think the only way is gps. Can anyone give me spme tipps pls?