9 posts
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)
620 posts
Location
Holland
Posted 10 April 2013 - 01:12 AM
After the last
else
turtle.placeUp()
turtle.forward()
You need an extra end
9 posts
Posted 10 April 2013 - 01:28 AM
Thanks! So far… Now i get: bios:338: [string "deckel"]:124: '<eof>' expected
Whats eof?
169 posts
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".
9 posts
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
620 posts
Location
Holland
Posted 10 April 2013 - 02:08 AM
You've got too much end's somewhere
169 posts
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.
620 posts
Location
Holland
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/>
620 posts
Location
Holland
Posted 10 April 2013 - 02:12 AM
Wooh this is fixed now look at the edit by the OP author just some comments up
169 posts
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
9 posts
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
620 posts
Location
Holland
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)
9 posts
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
169 posts
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).
169 posts
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.
9 posts
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
620 posts
Location
Holland
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
9 posts
Posted 10 April 2013 - 02:39 AM
I did! Something went wrong with the pasting. I edited.
620 posts
Location
Holland
Posted 10 April 2013 - 02:45 AM
Ah that's easier to read!
199 posts
Location
Switzerland
Posted 10 April 2013 - 02:51 AM
check your messages Ziron i send you a PM
9 posts
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
620 posts
Location
Holland
Posted 10 April 2013 - 02:52 AM
Cool!
199 posts
Location
Switzerland
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
9 posts
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? :)/>
199 posts
Location
Switzerland
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/>