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

I have some Problems with my farming programm! Need Help!

Started by Endoxx, 20 October 2012 - 10:41 PM
Endoxx #1
Posted 21 October 2012 - 12:41 AM
I created a farming programm but everytime i start it i get an error!

The code is:
a = 0
if a < 1 then
turtle.select(1)
if not turtle.compare() then
turtle.dig
turtle.forward(1)
turtle.dig
turtle.dorward(1)
turtle.turnRight(2)
turtle.select(2)
turtle.turnLeft(2)
turtle.select(1)
end
if turtle.compare()
turtle.turnRight(1)
turtle.dig
turtle.forward(1)
turtle.turnRight(2)
turtle.select(2)
turtle.place
turtle.turnLeft(1)
turtle.select(1)
end
end



The first slot in the turtle is fence the second seeds!
ChunLing #2
Posted 21 October 2012 - 03:23 AM
When you post code, you generally want to enclose it in code/spoiler tags, like this:
Spoiler
a = 0
if a < 1 then
	turtle.select(1)
	if not turtle.compare() then
		turtle.dig
		turtle.forward(1)
		turtle.dig
		turtle.dorward(1)
		turtle.turnRight(2)
		turtle.select(2)
		turtle.turnLeft(2)
		turtle.select(1)
	end
	if turtle.compare()
		turtle.turnRight(1)
		turtle.dig
		turtle.forward(1)
		turtle.turnRight(2)
		turtle.select(2)
		turtle.place
		turtle.turnLeft(1)
		turtle.select(1)
	end
end
You'll also want proper indentation.

I spotted some problems. First, "turtle.dorward(1)" isn't a turtle API supported function. I'm not sure whether it was supposed to be forward or what, because forward doesn't take a parameter.

Next, you have an odd structure where you end one "if then end" by going straight into another if. Usually in this case you want to use "if then elseif then end". Also, there is no "then" after the if anyway. You need a "then" after the conditional for each if/elseif, no exceptions. I don't see anything else that should throw an error, but you've got some wonky logic, I can't make out what this turtle is supposed to be doing when you say "turtle.turnRight(2) turtle.select(2) turtle.turnLeft(2) turtle.select(1)". This entire sequence can be replaced by "turtle.select(1)", cause thats the only command you don't end up canceling out. Also, the turn commands don't take parameters.

Last (or maybe first), you never change a, there's no chance of the overall "if" not being true. It looks like what you want is a simple "if turtle.compare() then … else … end" structure. That is, if turtle compare is true, do some stuff, and otherwise do some other stuff.

Also, this kind of post usually goes in "Ask a Pro"…you can repost it there if you still can't get it working. The programs forums are supposed to be for working code, even if it needs improvement. You can also post working code that isn't doing what you want in Ask a Pro. I suspect that even when you get this running it won't quite do what you want.
Edited on 21 October 2012 - 01:27 AM