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

[Error]Help my program won't work.

Started by Epicmonkeydude, 30 August 2012 - 04:18 PM
Epicmonkeydude #1
Posted 30 August 2012 - 06:18 PM
Thanks for the help guys but now I need more help. It needs to be able to sense when the seed slot is empty and go onto another seed slot.
_______________________________________________________________________________________________________________

function home(number)
for a = 1,number do
  turtle.forward()
end
end

while true do
	while not turtle.detect() do
		turtle.select(1)
		turtle.placeDown()
		turtle.forward()
		turtle.select(2)
	end
	while turtle.detectUp() do
		turtle.select(1)
		turtle.turnLeft()
		turtle.placeDown()
		turtle.forward()
		turtle.turnLeft()
	end
	while turtle.compare() do
		turtle.select(1)
		turtle.turnRight()
		turtle.placeDown()
		turtle.forward()
		turtle.turnRight()
	end
	turtle.select(3)
	 while turtle.compareDown(3) do
		 turtle.turnRight()
		 home(9)
		 turtle.turnRight()
		 return
	 end
end
OmegaVest #2
Posted 30 August 2012 - 08:28 PM
GAH!! Code tags! And format! If you format, I bet the problem will jump out at you. (Hint, you're missing an end. Also, you have a superfluous elseif, because there is no corresponding if)

Also, you don't need to do ==true or ==false. Just letting them be (or adding not in front in the case of falses) does the same thing.
Epicmonkeydude #3
Posted 30 August 2012 - 08:51 PM
GAH!! Code tags! And format! If you format, I bet the problem will jump out at you. (Hint, you're missing an end. Also, you have a superfluous elseif, because there is no corresponding if)

Also, you don't need to do ==true or ==false. Just letting them be (or adding not in front in the case of falses) does the same thing.
The code tags aren't actually in my proper code and could you please tell me where to put the end and the if. I just started with this like 2 or 3 days ago so I'm not knowledged about this stuff. :)/>/> Thanks B)/>/>
OmegaVest #4
Posted 30 August 2012 - 09:07 PM
Okay, first: when I say code tags, I mean put your code into code tags. There's a little button on the forum interface that looks like <>. It makes things look cleaner.

Secondly: You don't really need the if or elseif. Superfluous means unnecessary.

C: I'm not quite sure where you need to put the other end. Mostly because I can't presently follow your logic. Formatting helps.

So, for formatting, do this:
Every time you have a line that requires a comparative (ie. an if or a while), start the next line with three spaces.
Every time you have an end, take three spaces off the following line.

This makes it easy for coders to find where they are missing an end, or if they have an extra end. Or, in other languages like java, a close parens.

So, if I were making a program that did nothing but count, it would look a bit like this.


local afterLife =  100

function checkSummary(inVar)
   if inVar == afterLife then
	  return true
   elseif
      inVar == 15
      print("I'm fifteen for a moment")
      return false
   else
	  return false
   end
end

local i = 1

while not checkSummary(i) do
   i = i+1
end


Of course, this program is massively convoluted, but you can see how I format, and how easy you can see where my ifs, whiles, ends and such are. Also I addressed the whole ==true thing if you did not catch it.
Epicmonkeydude #5
Posted 31 August 2012 - 11:00 AM
Okay, first: when I say code tags, I mean put your code into code tags. There's a little button on the forum interface that looks like <>. It makes things look cleaner.

Secondly: You don't really need the if or elseif. Superfluous means unnecessary.

C: I'm not quite sure where you need to put the other end. Mostly because I can't presently follow your logic. Formatting helps.

So, for formatting, do this:
Every time you have a line that requires a comparative (ie. an if or a while), start the next line with three spaces.
Every time you have an end, take three spaces off the following line.

This makes it easy for coders to find where they are missing an end, or if they have an extra end. Or, in other languages like java, a close parens.

So, if I were making a program that did nothing but count, it would look a bit like this.


local afterLife =  100

function checkSummary(inVar)
   if inVar == afterLife then
	  return true
   elseif
	  inVar == 15
	  print("I'm fifteen for a moment")
	  return false
   else
	  return false
   end
end

local i = 1

while not checkSummary(i) do
   i = i+1
end


Of course, this program is massively convoluted, but you can see how I format, and how easy you can see where my ifs, whiles, ends and such are. Also I addressed the whole ==true thing if you did not catch it.
Ok reposted is that better :)/>/>
OmegaVest #6
Posted 31 August 2012 - 07:09 PM
Much better.

So, line 22, which is the start of a while loop (while turtle.compareTo(2) do), you need an end above that. While loops, unlike if blocks, always need an end.

Also, I get the sense you are trying to do something different than what you are currently doing. CompareTo checks to see whether the block in the currently selected block (which at line 22 is block 2) is the same as the called block (also 2). That while loop will run more or less forever, because it counts as true always. What you want is just compare() which needs no parameters.

If this is too confusing, pm me an outline of what this program is supposed to do. I'll see if I can give a bit more detailed help when I actually have time to explain it.
Epicmonkeydude #7
Posted 31 August 2012 - 10:07 PM
thanks I will fix and trie it then repost if it works or not.
Epicmonkeydude #8
Posted 03 September 2012 - 01:01 PM
reposted It and it works now I just need to make it end
OmegaVest #9
Posted 03 September 2012 - 09:16 PM
Okay. So, depending on how long you want it to run for, you can make a variable part of your conditional. Also, you can make it a function.

So, a question: what is the ending condition for this program? (ie. time, a block, etc)
Epicmonkeydude #10
Posted 04 September 2012 - 08:42 AM
I want it to end before the ends in this chunk of code
____________________________________________

turtle.select(3)
	 while turtle.compareDown(3) do
		 turtle.turnRight()
		 home(9)
		 turtle.turnRight()
		 (Here is where I want it to end)
	 end
end
chiloxsan #11
Posted 04 September 2012 - 09:28 AM
I want it to end before the ends in this chunk of code
____________________________________________

turtle.select(3)
	 while turtle.compareDown(3) do
		 turtle.turnRight()
		 home(9)
		 turtle.turnRight()
		 (Here is where I want it to end)
	 end
end

If you want to break out of the most recent loop you entered use break (with no parentheses/curly brackets), if you would like to return out of your function or quit your program if you are not in a function, use return.

Put one of those words where you want it to end
Epicmonkeydude #12
Posted 04 September 2012 - 11:13 AM
Thanks that's pretty simple I thought it would be harder chiloxsan. :D/>/>

Thanks for all the help OmegaVest. :P/>/>