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

Turtle wants an "end" that exists

Started by Ziron, 09 April 2013 - 11:09 PM
Ziron #1
Posted 10 April 2013 - 01:09 AM
Hi

I made a little program for turtles to shut quarry wholes. It changes slot automatically if one is empty and everything… nothing special.
But everytime i try to test the program i get an error. Well here is the code:


x=0
turtle.turnRight()
turtle.select(1)
if turtle.detect() then
t=0
turtle.turnLet()
else
t=1
turtle.turnLeft()
end
if turtle.detect() then

x=turtle.getItemCount(1)
  if x==0 then
   turtle.select(2)
   x=turtle.getItemCount(2)
	if x==0 then
	 turtle.select(3)
	 x=turtle.getItemCount(3)
   if x==0 then
	   turtle.select(4)
	   x=turtle.getItemCount(4)
	 if x==0 then
		 turtle.select(5)
		 x=turtle.getItemCount(5)
	  if x==0 then
   turtle.select(6)
   x=turtle.getItemCount(6)
	if x==0 then
	 turtle.select(7)
	 x=turtle.getItemCount(7)
if x==0 then
	   turtle.select(8)
	   x=turtle.getItemCount(8)
if x==0 then
		 turtle.select(9)
		 x=turtle.getItemCount(9)
	if x==0 then
   turtle.select(10)
   x=turtle.getItemCount(10)
	if x==0 then
	 turtle.select(11)
	 x=turtle.getItemCount(11)
   if x==0 then
	   turtle.select(12)
	   x=turtle.getItemCount(12)
	 if x==0 then
		 turtle.select(13)
		 x=turtle.getItemCount(13)
	   if x==0 then
	 turtle.select(14)
	 x=turtle.getItemCount(41)
   if x==0 then
	   turtle.select(15)
	   x=turtle.getItemCount(15)
	 if x==0 then
		 turtle.select(16)
		 x=turtle.getItemCount(16)


  end
	else
   turtle.placeUp()
   turtle.forward()
  end
	else
   turtle.placeUp()
   turtle.forward()
  end
	else
   turtle.placeUp()
   turtle.forward()
  end
	else
   turtle.placeUp()
   turtle.forward()
  end
	else
   turtle.placeUp()
   turtle.forward()
  end
	else
   turtle.placeUp()
   turtle.forward()
  end
	else
   turtle.placeUp()
   turtle.forward()
  end
	else
   turtle.placeUp()
   turtle.forward()
  end
	else
   turtle.placeUp()
   turtle.forward()
  end
	else
   turtle.placeUp()
   turtle.forward()
  end
	else
   turtle.placeUp()
   turtle.forward()
  end
	else
   turtle.placeUp()
   turtle.forward()
  end
	else
   turtle.placeUp()
   turtle.forward()
  end
	else
   turtle.placeUp()
   turtle.forward()
  end
	else
   turtle.placeUp()
   turtle.forward()

else
  if t=0 then
   turtle.turnLeft()
   turtle.forward()
   turtle.turnLeft()
  else
   turtle.turnRight()
   turtle.forward()
   turtle.turnRight()
  end
end

It says: bios:338: [string "deckel"]:123: 'end' expected (to close 'if' at line 11)

But my notepad++ says the 'if' is closed by the 'end' at line 133 (last line).

Thanks for any answer.

Greetings from Germany (sorry for possible english writing mistakes)
superaxander #2
Posted 10 April 2013 - 01:12 AM
After the last

        else
   turtle.placeUp()
   turtle.forward()
You need an extra end
Ziron #3
Posted 10 April 2013 - 01:28 AM
Thanks! So far… Now i get: bios:338: [string "deckel"]:124: '<eof>' expected

Whats eof?
SadKingBilly #4
Posted 10 April 2013 - 01:53 AM
EOF means "end-of-file". I'm not sure why that's the error it's giving you (maybe because it can't find an end to the if-statement), but the problem is with your last if-statement: "if t=0 then". You left out an equal sign, it should be: "if t==0 then".
Ziron #5
Posted 10 April 2013 - 01:59 AM
Thanks i forgot that issue with the double epuals :)/> But I still get the error. bios:338: [string "deckel"]:125: '<eof>' expected

It's something with the last 'else' witch is meant to be connected with the if at line 11 (second 'if') and I'm not sure if it is.

———-EDIT————-

Okay i fixed it by exchanging the 'else' with an 'if' same effect - no error :)/>

Spoiler
x=0
turtle.turnRight()
turtle.select(1)
if turtle.detect() then
t=0
turtle.turnLet()
else
t=1
turtle.turnLeft()
end
if turtle.detect() then

x=turtle.getItemCount(1)
if x==0 then
turtle.select(2)
x=turtle.getItemCount(2)
if x==0 then
turtle.select(3)
x=turtle.getItemCount(3)
if x==0 then
turtle.select(4)
x=turtle.getItemCount(4)
if x==0 then
turtle.select(5)
x=turtle.getItemCount(5)
if x==0 then
turtle.select(6)
x=turtle.getItemCount(6)
if x==0 then
turtle.select(7)
x=turtle.getItemCount(7)
if x==0 then
turtle.select(8)
x=turtle.getItemCount(8)
if x==0 then
turtle.select(9)
x=turtle.getItemCount(9)
if x==0 then
turtle.select(10)
x=turtle.getItemCount(10)
if x==0 then
turtle.select(11)
x=turtle.getItemCount(11)
if x==0 then
turtle.select(12)
x=turtle.getItemCount(12)
if x==0 then
turtle.select(13)
x=turtle.getItemCount(13)
  if x==0 then
turtle.select(14)
x=turtle.getItemCount(41)
if x==0 then
turtle.select(15)
x=turtle.getItemCount(15)
if x==0 then
turtle.select(16)
x=turtle.getItemCount(16)


  end
	else
   turtle.placeUp()
   turtle.forward()
  end
	else
   turtle.placeUp()
   turtle.forward()
  end
	else
   turtle.placeUp()
   turtle.forward()
  end
	else
   turtle.placeUp()
   turtle.forward()
  end
	else
   turtle.placeUp()
   turtle.forward()
  end
	else
   turtle.placeUp()
   turtle.forward()
  end
	else
   turtle.placeUp()
   turtle.forward()
  end
	else
   turtle.placeUp()
   turtle.forward()
  end
	else
   turtle.placeUp()
   turtle.forward()
  end
	else
   turtle.placeUp()
   turtle.forward()
  end
	else
   turtle.placeUp()
   turtle.forward()
  end
	else
   turtle.placeUp()
   turtle.forward()
  end
	else
   turtle.placeUp()
   turtle.forward()
  end
	else
   turtle.placeUp()
   turtle.forward()
  end
	else
   turtle.placeUp()
   turtle.forward()
  end

if turtle.detect() then
  if t==0 then
   turtle.turnLeft()
   turtle.forward()
   turtle.turnLeft()
  else
   turtle.turnRight()
   turtle.forward()
   turtle.turnRight()
  end

end
superaxander #6
Posted 10 April 2013 - 02:08 AM
You've got too much end's somewhere
SadKingBilly #7
Posted 10 April 2013 - 02:08 AM
It's hard to tell what the problem is because the tabs are so messed up in the original post. If you haven't updated your original post with the extra end that you added, then I think you actually have too many. But I really don't know.
superaxander #8
Posted 10 April 2013 - 02:09 AM
It's hard to tell what the problem is because the tabs are so messed up in the original post. If you haven't updated your original post with the extra end that you added, then I think you actually have too many. But I really don't know.
You got ninja'd :P/>
superaxander #9
Posted 10 April 2013 - 02:12 AM
Wooh this is fixed now look at the edit by the OP author just some comments up
SadKingBilly #10
Posted 10 April 2013 - 02:21 AM
Wooh this is fixed now look at the edit by the OP author just some comments up
Yeah, after I spend ten minutes fixing the tabbing in his code to find the problem. :angry:/>

Anyway, OP, I'm pretty sure the problem was that you had one-too-many of these (just so you know):

else
    turtle.placeUp()
    turtle.forward()
end
Ziron #11
Posted 10 April 2013 - 02:25 AM
Yes! :D/> okay here's my current status:

Current error: bios:338: [string "deckel"]:119: 'end' expected (to close while at line 12)

I just turned the 'if' ito a while so it is a loop but now it wants me again to put an 'end' anywhere…

Spoiler

x=0
turtle.turnRight()
turtle.select(1)
if turtle.detect() then
t=0
turtle.turnLeft()
else
t=1
turtle.turnLeft()
end
if turtle.detect() then
x=turtle.getItemCount(1)
if x==0 then
turtle.select(2)
x=turtle.getItemCount(2)
if x==0 then
turtle.select(3)
x=turtle.getItemCount(3)
if x==0 then
turtle.select(4)
x=turtle.getItemCount(4)
if x==0 then
turtle.select(5)
x=turtle.getItemCount(5)
if x==0 then
turtle.select(6)
x=turtle.getItemCount(6)
if x==0 then
turtle.select(7)
x=turtle.getItemCount(7)
if x==0 then
turtle.select(8)
x=turtle.getItemCount(8)
if x==0 then
turtle.select(9)
x=turtle.getItemCount(9)
if x==0 then
turtle.select(10)
x=turtle.getItemCount(10)
if x==0 then
turtle.select(11)
x=turtle.getItemCount(11)
if x==0 then
turtle.select(12)
x=turtle.getItemCount(12)
if x==0 then
turtle.select(13)
x=turtle.getItemCount(13)
  if x==0 then
turtle.select(14)
x=turtle.getItemCount(41)
if x==0 then
turtle.select(15)
x=turtle.getItemCount(15)
if x==0 then
turtle.select(16)
x=turtle.getItemCount(16)


  end
	else
   turtle.placeUp()
   turtle.forward()
  end
	else
   turtle.placeUp()
   turtle.forward()
  end
	else
   turtle.placeUp()
   turtle.forward()
  end
	else
   turtle.placeUp()
   turtle.forward()
  end
	else
   turtle.placeUp()
   turtle.forward()
  end
	else
   turtle.placeUp()
   turtle.forward()
  end
	else
   turtle.placeUp()
   turtle.forward()
  end
	else
   turtle.placeUp()
   turtle.forward()
  end
	else
   turtle.placeUp()
   turtle.forward()
  end
	else
   turtle.placeUp()
   turtle.forward()
  end
	else
   turtle.placeUp()
   turtle.forward()
  end
	else
   turtle.placeUp()
   turtle.forward()
  end
	else
   turtle.placeUp()
   turtle.forward()
  end
	else
   turtle.placeUp()
   turtle.forward()
  end
	else
   turtle.placeUp()
   turtle.forward()
end
if turtle.detect() then
  if t==0 then
   turtle.turnLeft()
   turtle.forward()
   turtle.turnLeft()
  else
   turtle.turnRight()
   turtle.forward()
   turtle.turnRight()
  end
end
superaxander #12
Posted 10 April 2013 - 02:28 AM
Yes! :D/>/> okay here's my current status:

Current error: bios:338: [string "deckel"]:119: 'end' expected (to close while at line 12)

I just turned the 'if' ito a while so it is a loop but now it wants me again to put an 'end' anywhere…

Spoiler

x=0
turtle.turnRight()
turtle.select(1)
if turtle.detect() then
t=0
turtle.turnLeft()
else
t=1
turtle.turnLeft()
end
if turtle.detect() then
x=turtle.getItemCount(1)
if x==0 then
turtle.select(2)
x=turtle.getItemCount(2)
if x==0 then
turtle.select(3)
x=turtle.getItemCount(3)
if x==0 then
turtle.select(4)
x=turtle.getItemCount(4)
if x==0 then
turtle.select(5)
x=turtle.getItemCount(5)
if x==0 then
turtle.select(6)
x=turtle.getItemCount(6)
if x==0 then
turtle.select(7)
x=turtle.getItemCount(7)
if x==0 then
turtle.select(8)
x=turtle.getItemCount(8)
if x==0 then
turtle.select(9)
x=turtle.getItemCount(9)
if x==0 then
turtle.select(10)
x=turtle.getItemCount(10)
if x==0 then
turtle.select(11)
x=turtle.getItemCount(11)
if x==0 then
turtle.select(12)
x=turtle.getItemCount(12)
if x==0 then
turtle.select(13)
x=turtle.getItemCount(13)
  if x==0 then
turtle.select(14)
x=turtle.getItemCount(41)
if x==0 then
turtle.select(15)
x=turtle.getItemCount(15)
if x==0 then
turtle.select(16)
x=turtle.getItemCount(16)


  end
	else
   turtle.placeUp()
   turtle.forward()
  end
	else
   turtle.placeUp()
   turtle.forward()
  end
	else
   turtle.placeUp()
   turtle.forward()
  end
	else
   turtle.placeUp()
   turtle.forward()
  end
	else
   turtle.placeUp()
   turtle.forward()
  end
	else
   turtle.placeUp()
   turtle.forward()
  end
	else
   turtle.placeUp()
   turtle.forward()
  end
	else
   turtle.placeUp()
   turtle.forward()
  end
	else
   turtle.placeUp()
   turtle.forward()
  end
	else
   turtle.placeUp()
   turtle.forward()
  end
	else
   turtle.placeUp()
   turtle.forward()
  end
	else
   turtle.placeUp()
   turtle.forward()
  end
	else
   turtle.placeUp()
   turtle.forward()
  end
	else
   turtle.placeUp()
   turtle.forward()
  end
	else
   turtle.placeUp()
   turtle.forward()
end
if turtle.detect() then
  if t==0 then
   turtle.turnLeft()
   turtle.forward()
   turtle.turnLeft()
  else
   turtle.turnRight()
   turtle.forward()
   turtle.turnRight()
  end
end
Please oh please indent your code(you know TAB's)
Ziron #13
Posted 10 April 2013 - 02:28 AM
Wooh this is fixed now look at the edit by the OP author just some comments up
Yeah, after I spend ten minutes fixing the tabbing in his code to find the problem. :angry:/>

Anyway, OP, I'm pretty sure the problem was that you had one-too-many of these (just so you know):

else
	turtle.placeUp()
	turtle.forward()
end
No there are 15 ifs and 15 elses
SadKingBilly #14
Posted 10 April 2013 - 02:29 AM
But I don't see a "while" in the code you posted. :blink:/>

Honestly, if you explain how you want your code to work, we can show you a much easier and quicker way to do it (that doesn't involve all the ifs).
SadKingBilly #15
Posted 10 April 2013 - 02:31 AM
Wooh this is fixed now look at the edit by the OP author just some comments up
Yeah, after I spend ten minutes fixing the tabbing in his code to find the problem. :angry:/>

Anyway, OP, I'm pretty sure the problem was that you had one-too-many of these (just so you know):

else
	turtle.placeUp()
	turtle.forward()
end
No there are 15 ifs and 15 elses
That's weird, because in the code you posted originally (after adding the extra end), there were eighteen ifs, eighteen elses, and nineteen ends.
Ziron #16
Posted 10 April 2013 - 02:34 AM
Please oh please indent your code(you know TAB's)

Spoiler

x=0
turtle.turnRight()
turtle.select(1)

if turtle.detect() then
 t=0
 turtle.turnLeft()
else
 t=1
 turtle.turnLeft()
end

while turtle.detect() do
 
x=turtle.getItemCount(1)
if x==0 then
 turtle.select(2)
 x=turtle.getItemCount(2)

if x==0 then
 turtle.select(3)
 x=turtle.getItemCount(3)

if x==0 then
 turtle.select(4)
 x=turtle.getItemCount(4)

if x==0 then
 turtle.select(5)
 x=turtle.getItemCount(5)

if x==0 then
 turtle.select(6)
 x=turtle.getItemCount(6)

if x==0 then
 turtle.select(7)
 x=turtle.getItemCount(7)

if x==0 then
 turtle.select(8)
 x=turtle.getItemCount(8)

if x==0 then
 turtle.select(9)
 x=turtle.getItemCount(9)

if x==0 then
 turtle.select(10)
 x=turtle.getItemCount(10)

if x==0 then
 turtle.select(11)
 x=turtle.getItemCount(11)

if x==0 then
 turtle.select(12)
 x=turtle.getItemCount(12)

if x==0 then
 turtle.select(13)
 x=turtle.getItemCount(13)

if x==0 then
 turtle.select(14)
 x=turtle.getItemCount(41)

if x==0 then
 turtle.select(15)
 x=turtle.getItemCount(15)

if x==0 then
 turtle.select(16)
 x=turtle.getItemCount(16)

end

else
   turtle.placeUp()
   turtle.forward()
end

else
   turtle.placeUp()
   turtle.forward()
end

else
   turtle.placeUp()
   turtle.forward()
end

else
   turtle.placeUp()
   turtle.forward()
end

else
   turtle.placeUp()
   turtle.forward()
end
 
else
   turtle.placeUp()
   turtle.forward()
end

else
   turtle.placeUp()
   turtle.forward()
end

else
   turtle.placeUp()
   turtle.forward()
end
 
else
   turtle.placeUp()
   turtle.forward()
end

else
   turtle.placeUp()
   turtle.forward()
end

else
   turtle.placeUp()
   turtle.forward()
end

else
   turtle.placeUp()
   turtle.forward()
end

else
   turtle.placeUp()
   turtle.forward()
end

else
   turtle.placeUp()
   turtle.forward()
end

else
   turtle.placeUp()
   turtle.forward()
end

 

if turtle.detect() then
  if t==0 then
   turtle.turnLeft()
   turtle.forward()
   turtle.turnLeft()
  else
   turtle.turnRight()
   turtle.forward()
   turtle.turnRight()
  end
 
end
superaxander #17
Posted 10 April 2013 - 02:36 AM
Please oh please indent your code(you know TAB's)

Spoiler
x=0
turtle.turnRight()
turtle.select(1)
if turtle.detect() then
t=0
turtle.turnLeft()
else
t=1
turtle.turnLeft()
end
if turtle.detect() then

x=turtle.getItemCount(1)
if x==0 then
turtle.select(2)
x=turtle.getItemCount(2)
if x==0 then
turtle.select(3)
x=turtle.getItemCount(3)
if x==0 then
turtle.select(4)
x=turtle.getItemCount(4)
if x==0 then
turtle.select(5)
x=turtle.getItemCount(5)
if x==0 then
turtle.select(6)
x=turtle.getItemCount(6)
if x==0 then
turtle.select(7)
x=turtle.getItemCount(7)
if x==0 then
turtle.select(8)
x=turtle.getItemCount(8)
if x==0 then
turtle.select(9)
x=turtle.getItemCount(9)
if x==0 then
turtle.select(10)
x=turtle.getItemCount(10)
if x==0 then
turtle.select(11)
x=turtle.getItemCount(11)
if x==0 then
turtle.select(12)
x=turtle.getItemCount(12)
if x==0 then
turtle.select(13)
x=turtle.getItemCount(13)
if x==0 then
turtle.select(14)
x=turtle.getItemCount(41)
if x==0 then
turtle.select(15)
x=turtle.getItemCount(15)
if x==0 then
turtle.select(16)
x=turtle.getItemCount(16)
end
else
   turtle.placeUp()
   turtle.forward()
end
else
   turtle.placeUp()
   turtle.forward()
end
else
   turtle.placeUp()
   turtle.forward()
end
else
   turtle.placeUp()
   turtle.forward()
end
else
   turtle.placeUp()
   turtle.forward()
end

else
   turtle.placeUp()
   turtle.forward()
end
else
   turtle.placeUp()
   turtle.forward()
end
else
   turtle.placeUp()
   turtle.forward()
end

else
   turtle.placeUp()
   turtle.forward()
end
else
   turtle.placeUp()
   turtle.forward()
end
else
   turtle.placeUp()
   turtle.forward()
end
else
   turtle.placeUp()
   turtle.forward()
end
else
   turtle.placeUp()
   turtle.forward()
end
else
   turtle.placeUp()
   turtle.forward()
end
else
   turtle.placeUp()
   turtle.forward()
end

if turtle.detect() then
  if t==0 then
   turtle.turnLeft()
   turtle.forward()
   turtle.turnLeft()
  else
   turtle.turnRight()
   turtle.forward()
   turtle.turnRight()
  end

end
You haven't indented the code directly below the if and you didn't ident the if's inside each other
Ziron #18
Posted 10 April 2013 - 02:39 AM
I did! Something went wrong with the pasting. I edited.
superaxander #19
Posted 10 April 2013 - 02:45 AM
Ah that's easier to read!
LordIkol #20
Posted 10 April 2013 - 02:51 AM
check your messages Ziron i send you a PM
Ziron #21
Posted 10 April 2013 - 02:51 AM
I fixed the 'end'-thing
Spoiler

x=0
turtle.turnRight()
turtle.select(1)

if turtle.detect() then
t=0
turtle.turnLeft()
else
t=1
turtle.turnLeft()
end

while not turtle.detect() do

x=turtle.getItemCount(1)
if x==0 then
turtle.select(2)
x=turtle.getItemCount(2)
else
   turtle.placeUp()
   turtle.forward()
end

if x==0 then
turtle.select(3)
x=turtle.getItemCount(3)
else
   turtle.placeUp()
   turtle.forward()
end

if x==0 then
turtle.select(4)
x=turtle.getItemCount(4)
else
   turtle.placeUp()
   turtle.forward()
end

if x==0 then
turtle.select(5)
x=turtle.getItemCount(5)
else
   turtle.placeUp()
   turtle.forward()
end

if x==0 then
turtle.select(6)
x=turtle.getItemCount(6)
else
   turtle.placeUp()
   turtle.forward()
end

if x==0 then
turtle.select(7)
x=turtle.getItemCount(7)
else
   turtle.placeUp()
   turtle.forward()
end

if x==0 then
turtle.select(8)
x=turtle.getItemCount(8)
else
   turtle.placeUp()
   turtle.forward()
end

if x==0 then
turtle.select(9)
x=turtle.getItemCount(9)
else
   turtle.placeUp()
   turtle.forward()
end

if x==0 then
turtle.select(10)
x=turtle.getItemCount(10)
else
   turtle.placeUp()
   turtle.forward()
end

if x==0 then
turtle.select(11)
x=turtle.getItemCount(11)
else
   turtle.placeUp()
   turtle.forward()
end

if x==0 then
turtle.select(12)
x=turtle.getItemCount(12)
else
   turtle.placeUp()
   turtle.forward()
end

if x==0 then
turtle.select(13)
x=turtle.getItemCount(13)
else
   turtle.placeUp()
   turtle.forward()
end

if x==0 then
turtle.select(14)
x=turtle.getItemCount(41)
else
   turtle.placeUp()
   turtle.forward()
end

if x==0 then
turtle.select(15)
x=turtle.getItemCount(15)
else
   turtle.placeUp()
   turtle.forward()
end

if x==0 then
turtle.select(16)
x=turtle.getItemCount(16)
else
   turtle.placeUp()
   turtle.forward()
end

end


if turtle.detect() then
if t==0 then
   turtle.turnLeft()
   turtle.forward()
   turtle.turnLeft()
else
   turtle.turnRight()
   turtle.forward()
   turtle.turnRight()
end

end


superaxander #22
Posted 10 April 2013 - 02:52 AM
Cool!
LordIkol #23
Posted 10 April 2013 - 03:03 AM
here is a version thats a little bit shorter and should do the same
http://pastebin.com/jN0seJz4
Ziron #24
Posted 10 April 2013 - 03:09 AM
Thanks! :)/> 'return i' means goin from 2 to 3 for example? I did'nt know that i could use variables for getItemCount().

Man lernt nie aus wa? :)/>
LordIkol #25
Posted 10 April 2013 - 03:15 AM
If you look at the Code now i put in some comments in German :)/>

return i bewirkt zum einen das die funktion beendet wird
zum 2. gibt es den wert i zurück wenn man die funktion aufruft

du kannst dadurch sagen
actualSlot = freierslot()
print(actualSlot)
und weisst so welcher slot gewählt wurde

Sorry for using german :D/>